-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathperformance.xp
executable file
·228 lines (187 loc) · 5.5 KB
/
performance.xp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/expect
#-*-sh-*-
# This expect script performs performance measurements on mserv. It
# requires a user account to with username "root" with password
# "root". It also requires at least one song in one album and an
# otherwise working configuration.
#
# If you want to add tests, do that below the "Tests start here"
# marker (below).
# Hang if something unexpected happens
set timeout -1
# Run benchmarkee a couple of times and store the min, max and
# average run time in the global benchmark_results list.
set benchmark_results []
proc benchmark { description benchmarkee } {
global benchmark_results
global computerroot
global humanroot
send_error "\n\n***\n*** $description:\n***\n\n"
# Setting precision_percent to 10.0 should mean that the average
# result returned by this function should be within 10% of the
# true average
set precision_percent 10.0
set precision_max_factor [expr (100.0 + $precision_percent) / 100.0]
set precision_min_factor [expr (100.0 - $precision_percent) / 100.0]
set min_runtime 0
set max_runtime 0
set average_runtime 0
set i 1
set total_runtime 0
while { 1 } {
set t0 [clock clicks -milliseconds]
eval $benchmarkee
set t1 [clock clicks -milliseconds]
set runtime [expr $t1 - $t0]
set total_runtime [expr $total_runtime + $runtime]
set average_runtime [expr 1.0 * $total_runtime / $i]
if { $i == 1 } {
set max_runtime $runtime
set min_runtime $runtime
}
if { $runtime > $max_runtime } {
set max_runtime $runtime
}
if { $runtime < $min_runtime } {
set min_runtime $runtime
}
# Break if we have enough precision
if { $i > 10 } {
set max_allowed [expr $average_runtime * $precision_max_factor]
set min_allowed [expr $average_runtime * $precision_min_factor]
set max_possible [expr ($total_runtime + $max_runtime) / ($i + 1.0)]
set min_possible [expr ($total_runtime + $min_runtime) / ($i + 1.0)]
# send_error "Johan: Measured: $min_runtime-$average_runtime-$max_runtime Allowed: $min_allowed-$max_allowed Possible: $min_possible-$max_possible\n"
if { $min_possible >= $min_allowed &&
$max_possible <= $max_allowed} {
break
}
}
set i [expr $i + 1]
}
set result(description) $description
set result(max_runtime) $max_runtime
set result(min_runtime) $min_runtime
set result(average_runtime) $average_runtime
lappend benchmark_results [array get result]
}
# Log two roots for benchmarking
spawn telnet localhost 4444
set humanroot $spawn_id
expect "USER"
send "user root\n"
expect "PASS"
send "pass root\n"
expect "Welcome root"
spawn telnet localhost 4444
set computerroot $spawn_id
expect "USER"
expect "\n.\n"
send "user root\n"
expect "PASS"
expect "\n.\n"
send "pass root rtcomputer\n"
expect "202"
expect "Welcome root"
expect "\n.\n"
expect -i $humanroot "root has connected"
# Back to the human root
set spawn_id $humanroot
#
# Tests start here
#
# Benchmark the "queue" command
benchmark {Running "queue" over and over} {
send "queue\n"
expect "There are no tracks in the queue"
}
# Benchmark the "queue" command while a song is playing
send "play\n"
expect "Playing"
expect -i $computerroot "=622\trandom"
benchmark {Running "queue" over and over while a song is playing} {
send "queue\n"
expect "There are no tracks in the queue"
}
send "stop\n"
expect "stopped"
expect -i $computerroot "=623\troot"
# Benchmark the "rate" command while a song is playing
send "play\n"
expect "Playing"
expect -i $computerroot "=622\trandom"
send_user "Waiting for music to get started..."
sleep 5
benchmark {Rating a song over and over while it is playing} {
send "rate neutral\n"
expect "has been rated NEUTRAL by root"
expect -i $computerroot "=615"
expect -i $computerroot "NEUTRAL"
}
send "stop\n"
expect "stopped"
expect -i $computerroot "=623\troot"
# Benchmark "play" + "stop"
benchmark {Running "play" + "stop" over and over} {
send "play\n"
expect "Playing"
expect -i $computerroot "=622\trandom"
send "stop\n"
expect "stopped"
expect -i $computerroot "=623\troot"
}
# Benchmark "play"+"pause"+"play"+"next"+"stop"
benchmark {The "play"-"pause"-"play"-"next"-"stop" cycle} {
send "play\n"
expect "Playing"
expect -i $computerroot "=622\trandom"
send "status\n"
expect "Playing"
send "queue\n"
expect "no tracks in the queue"
send "pause\n"
expect "paused"
expect -i $computerroot "=606\troot"
send "status\n"
expect "Paused"
send "queue\n"
expect "no tracks in the queue"
send "play\n"
expect "resumed"
expect -i $computerroot "=605\troot"
send "status\n"
expect "Playing"
send "queue\n"
expect "no tracks in the queue"
send "next\n"
expect "Track skipped"
expect "Playing:"
expect -i $computerroot "=629\troot"
expect -i $computerroot "=622\trandom"
send "status\n"
expect "Playing"
send "queue\n"
expect "no tracks in the queue"
send "stop\n"
expect "stopped"
expect -i $computerroot "=623\troot"
send "status\n"
expect "Nothing currently playing"
send "queue\n"
expect "no tracks in the queue"
}
#
# Tests end here
#
# Present the results
send_error "\n\n****** Results: ******\n"
foreach list_result $benchmark_results {
array set result $list_result
send_error [format \
"\n%s took %dms-%dms, average time was %.1fms\n" \
$result(description) \
$result(min_runtime) \
$result(max_runtime) \
$result(average_runtime)]
}
send_error "\n"