4
4
5
5
mutable struct Trial
6
6
params:: Parameters
7
- times:: Vector{Float64}
7
+ realtimes:: Vector{Float64}
8
+ cputimes:: Vector{Float64}
8
9
gctimes:: Vector{Float64}
9
10
memory:: Int
10
11
allocs:: Int
11
12
end
12
13
13
- Trial (params:: Parameters ) = Trial (params, Float64[], Float64[], typemax (Int), typemax (Int))
14
+ Trial (params:: Parameters ) = Trial (params, Float64[], Float64[], Float64[], typemax (Int), typemax (Int))
14
15
15
16
@compat function Base.:(== )(a:: Trial , b:: Trial )
16
17
return a. params == b. params &&
17
- a. times == b. times &&
18
+ a. realtimes == b. realtimes &&
19
+ a. cputimes == b. cputimes &&
18
20
a. gctimes == b. gctimes &&
19
21
a. memory == b. memory &&
20
22
a. allocs == b. allocs
21
23
end
22
24
23
- Base. copy (t:: Trial ) = Trial (copy (t. params), copy (t. times ), copy (t. gctimes), t. memory, t. allocs)
25
+ Base. copy (t:: Trial ) = Trial (copy (t. params), copy (t. realtimes), copy (t . cputimes ), copy (t. gctimes), t. memory, t. allocs)
24
26
25
- function Base. push! (t:: Trial , time, gctime, memory, allocs)
26
- push! (t. times, time)
27
+ function Base. push! (t:: Trial , realtime, cputime, gctime, memory, allocs)
28
+ push! (t. realtimes, realtime)
29
+ push! (t. cputimes, cputime)
27
30
push! (t. gctimes, gctime)
28
31
memory < t. memory && (t. memory = memory)
29
32
allocs < t. allocs && (t. allocs = allocs)
30
33
return t
31
34
end
32
35
33
36
function Base. deleteat! (t:: Trial , i)
34
- deleteat! (t. times, i)
37
+ deleteat! (t. realtimes, i)
38
+ deleteat! (t. cputimes, i)
35
39
deleteat! (t. gctimes, i)
36
40
return t
37
41
end
38
42
39
- Base. length (t:: Trial ) = length (t. times )
40
- Base. getindex (t:: Trial , i:: Number ) = push! (Trial (t. params), t. times [i], t. gctimes[i], t. memory, t. allocs)
41
- Base. getindex (t:: Trial , i) = Trial (t. params, t. times [i], t. gctimes[i], t. memory, t. allocs)
43
+ Base. length (t:: Trial ) = length (t. realtimes )
44
+ Base. getindex (t:: Trial , i:: Number ) = push! (Trial (t. params), t. realtimes[i], t . cputimes [i], t. gctimes[i], t. memory, t. allocs)
45
+ Base. getindex (t:: Trial , i) = Trial (t. params, t. realtimes[i], t . cputimes [i], t. gctimes[i], t. memory, t. allocs)
42
46
Base. endof (t:: Trial ) = length (t)
43
47
44
48
function Base. sort! (t:: Trial )
45
- inds = sortperm (t. times)
46
- t. times = t. times[inds]
49
+ inds = sortperm (t. realtimes)
50
+ t. realtimes = t. realtimes[inds]
51
+ t. cputimes = t. cputimes[inds]
47
52
t. gctimes = t. gctimes[inds]
48
53
return t
49
54
end
50
55
51
56
Base. sort (t:: Trial ) = sort! (copy (t))
52
57
53
- Base. time (t:: Trial ) = time (minimum (t))
58
+ realtime (t:: Trial ) = realtime (minimum (t))
59
+ cputime (t:: Trial ) = cputime (minimum (t))
54
60
gctime (t:: Trial ) = gctime (minimum (t))
55
61
memory (t:: Trial ) = t. memory
56
62
allocs (t:: Trial ) = t. allocs
@@ -66,7 +72,7 @@ function skewcutoff(values)
66
72
return length (current_values) + 1
67
73
end
68
74
69
- skewcutoff (t:: Trial ) = skewcutoff (t. times )
75
+ skewcutoff (t:: Trial ) = skewcutoff (t. realtimes )
70
76
71
77
function rmskew! (t:: Trial )
72
78
sort! (t)
@@ -88,19 +94,21 @@ trim(t::Trial, percentage = 0.1) = t[1:max(1, floor(Int, length(t) - (length(t)
88
94
89
95
mutable struct TrialEstimate
90
96
params:: Parameters
91
- time:: Float64
97
+ realtime:: Float64
98
+ cputime:: Float64
92
99
gctime:: Float64
93
100
memory:: Int
94
101
allocs:: Int
95
102
end
96
103
97
- function TrialEstimate (trial:: Trial , t, gct )
98
- return TrialEstimate (params (trial), t, gct , memory (trial), allocs (trial))
104
+ function TrialEstimate (trial:: Trial , realtime, cputime, gctime )
105
+ return TrialEstimate (params (trial), realtime, cputime, gctime , memory (trial), allocs (trial))
99
106
end
100
107
101
108
@compat function Base.:(== )(a:: TrialEstimate , b:: TrialEstimate )
102
109
return a. params == b. params &&
103
- a. time == b. time &&
110
+ a. realtime == b. realtime &&
111
+ a. cputime == b. cputime &&
104
112
a. gctime == b. gctime &&
105
113
a. memory == b. memory &&
106
114
a. allocs == b. allocs
@@ -109,21 +117,22 @@ end
109
117
Base. copy (t:: TrialEstimate ) = TrialEstimate (copy (t. params), t. time, t. gctime, t. memory, t. allocs)
110
118
111
119
function Base. minimum (trial:: Trial )
112
- i = indmin (trial. times )
113
- return TrialEstimate (trial, trial. times [i], trial. gctimes[i])
120
+ i = indmin (trial. realtimes )
121
+ return TrialEstimate (trial, trial. realtimes[i], trial . cputimes [i], trial. gctimes[i])
114
122
end
115
123
116
124
function Base. maximum (trial:: Trial )
117
- i = indmax (trial. times )
118
- return TrialEstimate (trial, trial. times [i], trial. gctimes[i])
125
+ i = indmax (trial. realtimes )
126
+ return TrialEstimate (trial, trial. realtimes[i], trial . cputimes [i], trial. gctimes[i])
119
127
end
120
128
121
- Base. median (trial:: Trial ) = TrialEstimate (trial, median (trial. times ), median (trial. gctimes))
122
- Base. mean (trial:: Trial ) = TrialEstimate (trial, mean (trial. times ), mean (trial. gctimes))
129
+ Base. median (trial:: Trial ) = TrialEstimate (trial, median (trial. realtimes), median (trial . cputimes ), median (trial. gctimes))
130
+ Base. mean (trial:: Trial ) = TrialEstimate (trial, mean (trial. realtimes), mean (trial . cputimes ), mean (trial. gctimes))
123
131
124
- Base. isless (a:: TrialEstimate , b:: TrialEstimate ) = isless (time (a), time (b))
132
+ Base. isless (a:: TrialEstimate , b:: TrialEstimate ) = isless (realtime (a), realtime (b))
125
133
126
- Base. time (t:: TrialEstimate ) = t. time
134
+ realtime (t:: TrialEstimate ) = t. realtime
135
+ cputime (t:: TrialEstimate ) = t. cputime
127
136
gctime (t:: TrialEstimate ) = t. gctime
128
137
memory (t:: TrialEstimate ) = t. memory
129
138
allocs (t:: TrialEstimate ) = t. allocs
@@ -135,23 +144,26 @@ params(t::TrialEstimate) = t.params
135
144
136
145
mutable struct TrialRatio
137
146
params:: Parameters
138
- time:: Float64
147
+ realtime:: Float64
148
+ cputime:: Float64
139
149
gctime:: Float64
140
150
memory:: Float64
141
151
allocs:: Float64
142
152
end
143
153
144
154
@compat function Base.:(== )(a:: TrialRatio , b:: TrialRatio )
145
155
return a. params == b. params &&
146
- a. time == b. time &&
156
+ a. realtime == b. realtime &&
157
+ a. cputime == b. cputime &&
147
158
a. gctime == b. gctime &&
148
159
a. memory == b. memory &&
149
160
a. allocs == b. allocs
150
161
end
151
162
152
- Base. copy (t:: TrialRatio ) = TrialRatio (copy (t. params), t. time , t. gctime, t. memory, t. allocs)
163
+ Base. copy (t:: TrialRatio ) = TrialRatio (copy (t. params), t. realtime, t . cputime , t. gctime, t. memory, t. allocs)
153
164
154
- Base. time (t:: TrialRatio ) = t. time
165
+ realtime (t:: TrialRatio ) = t. realtime
166
+ cputime (t:: TrialRatio ) = t. cputime
155
167
gctime (t:: TrialRatio ) = t. gctime
156
168
memory (t:: TrialRatio ) = t. memory
157
169
allocs (t:: TrialRatio ) = t. allocs
@@ -168,37 +180,42 @@ function ratio(a::TrialEstimate, b::TrialEstimate)
168
180
ttol = max (params (a). time_tolerance, params (b). time_tolerance)
169
181
mtol = max (params (a). memory_tolerance, params (b). memory_tolerance)
170
182
p = Parameters (params (a); time_tolerance = ttol, memory_tolerance = mtol)
171
- return TrialRatio (p, ratio (time (a), time (b)), ratio (gctime (a), gctime (b)),
172
- ratio (memory (a), memory (b)), ratio (allocs (a), allocs (b)))
183
+ return TrialRatio (p, ratio (realtime (a), realtime (b)), ratio (cputime (a), cputime (b)),
184
+ ratio (gctime (a), gctime (b)), ratio (memory (a), memory (b)),
185
+ ratio (allocs (a), allocs (b)))
173
186
end
174
187
175
- gcratio (t:: TrialEstimate ) = ratio (gctime (t), time (t))
188
+ gcratio (t:: TrialEstimate ) = ratio (gctime (t), realtime (t))
189
+ cpuratio (t:: TrialEstimate ) = ratio (cputime (t), realtime (t))
176
190
177
191
# #################
178
192
# TrialJudgement #
179
193
# #################
180
194
181
195
struct TrialJudgement
182
196
ratio:: TrialRatio
183
- time:: Symbol
197
+ realtime:: Symbol
198
+ cputime:: Symbol
184
199
memory:: Symbol
185
200
end
186
201
187
202
function TrialJudgement (r:: TrialRatio )
188
203
ttol = params (r). time_tolerance
189
204
mtol = params (r). memory_tolerance
190
- return TrialJudgement (r, judge (time (r), ttol), judge (memory (r), mtol))
205
+ return TrialJudgement (r, judge (realtime (r), ttol), judge ( cputime (r), ttol), judge (memory (r), mtol))
191
206
end
192
207
193
208
@compat function Base.:(== )(a:: TrialJudgement , b:: TrialJudgement )
194
209
return a. ratio == b. ratio &&
195
- a. time == b. time &&
210
+ a. realtime == b. realtime &&
211
+ a. cputime == b. cputime &&
196
212
a. memory == b. memory
197
213
end
198
214
199
- Base. copy (t:: TrialJudgement ) = TrialJudgement (copy (t. params), t. time , t. memory)
215
+ Base. copy (t:: TrialJudgement ) = TrialJudgement (copy (t. params), t. realtime, t . cputime , t. memory)
200
216
201
- Base. time (t:: TrialJudgement ) = t. time
217
+ realtime (t:: TrialJudgement ) = t. realtime
218
+ cputime (t:: TrialJudgement ) = t. cputime
202
219
memory (t:: TrialJudgement ) = t. memory
203
220
ratio (t:: TrialJudgement ) = t. ratio
204
221
params (t:: TrialJudgement ) = params (ratio (t))
@@ -221,9 +238,9 @@ function judge(ratio::Real, tolerance::Float64)
221
238
end
222
239
end
223
240
224
- isimprovement (t:: TrialJudgement ) = time (t) == :improvement || memory (t) == :improvement
225
- isregression (t:: TrialJudgement ) = time (t) == :regression || memory (t) == :regression
226
- isinvariant (t:: TrialJudgement ) = time (t) == :invariant && memory (t) == :invariant
241
+ isimprovement (t:: TrialJudgement ) = realtime (t) == :improvement || cputime (t) == :improvement || memory (t) == :improvement
242
+ isregression (t:: TrialJudgement ) = realtime (t) == :regression || cputime (t) == :regression || memory (t) == :regression
243
+ isinvariant (t:: TrialJudgement ) = realtime (t) == :invariant && cputime (t) == :invariant && memory (t) == :invariant
227
244
228
245
# ##################
229
246
# Pretty Printing #
@@ -262,10 +279,10 @@ function prettymemory(b)
262
279
return string (@sprintf (" %.2f" , value), " " , units)
263
280
end
264
281
265
- Base. show (io:: IO , t:: Trial ) = print (io, " Trial(" , prettytime (time (t)), " )" )
266
- Base. show (io:: IO , t:: TrialEstimate ) = print (io, " TrialEstimate(" , prettytime (time (t)), " )" )
267
- Base. show (io:: IO , t:: TrialRatio ) = print (io, " TrialRatio(" , prettypercent (time (t)), " )" )
268
- Base. show (io:: IO , t:: TrialJudgement ) = print (io, " TrialJudgement(" , prettydiff (time (ratio (t))), " => " , time (t), " )" )
282
+ Base. show (io:: IO , t:: Trial ) = print (io, " Trial(" , prettytime (realtime (t)), " )" )
283
+ Base. show (io:: IO , t:: TrialEstimate ) = print (io, " TrialEstimate(" , prettytime (realtime (t)), " )" )
284
+ Base. show (io:: IO , t:: TrialRatio ) = print (io, " TrialRatio(" , prettypercent (realtime (t)), " )" )
285
+ Base. show (io:: IO , t:: TrialJudgement ) = print (io, " TrialJudgement(" , prettydiff (realtime (ratio (t))), " => " , realtime (t), " )" )
269
286
270
287
@compat function Base. show (io:: IO , :: MIME"text/plain" , t:: Trial )
271
288
if length (t) > 0
@@ -275,10 +292,10 @@ Base.show(io::IO, t::TrialJudgement) = print(io, "TrialJudgement(", prettydiff(t
275
292
avg = mean (t)
276
293
memorystr = string (prettymemory (memory (min)))
277
294
allocsstr = string (allocs (min))
278
- minstr = string (prettytime (time (min)), " (" , prettypercent (gcratio (min)), " GC)" )
279
- maxstr = string (prettytime (time (med)), " (" , prettypercent (gcratio (med)), " GC)" )
280
- medstr = string (prettytime (time (avg)), " (" , prettypercent (gcratio (avg)), " GC)" )
281
- meanstr = string (prettytime (time (max)), " (" , prettypercent (gcratio (max)), " GC)" )
295
+ minstr = string (prettytime (realtime (min)), " (" , prettypercent ( cpuratio (min)) , " CPU, " , prettypercent (gcratio (min)), " GC)" )
296
+ maxstr = string (prettytime (realtime (med)), " (" , prettypercent ( cpuratio (med)) , " CPU, " , prettypercent (gcratio (med)), " GC)" )
297
+ medstr = string (prettytime (realtime (avg)), " (" , prettypercent ( cpuratio (avg)) , " CPU, " , prettypercent (gcratio (avg)), " GC)" )
298
+ meanstr = string (prettytime (realtime (max)), " (" , prettypercent ( cpuratio (max)) , " CPU, " , prettypercent (gcratio (max)), " GC)" )
282
299
else
283
300
memorystr = " N/A"
284
301
allocsstr = " N/A"
@@ -302,22 +319,25 @@ end
302
319
303
320
@compat function Base. show (io:: IO , :: MIME"text/plain" , t:: TrialEstimate )
304
321
println (io, " BenchmarkTools.TrialEstimate: " )
305
- println (io, " time: " , prettytime (time (t)))
306
- println (io, " gctime: " , prettytime (gctime (t)), " (" , prettypercent (gctime (t) / time (t))," )" )
322
+ println (io, " realtime: " , prettytime (realtime (t)))
323
+ println (io, " cputime: " , prettytime (cputime (t)), " (" , prettypercent (cputime (t) / realtime (t))," )" )
324
+ println (io, " gctime: " , prettytime (gctime (t)), " (" , prettypercent (gctime (t) / realtime (t))," )" )
307
325
println (io, " memory: " , prettymemory (memory (t)))
308
326
print (io, " allocs: " , allocs (t))
309
327
end
310
328
311
329
@compat function Base. show (io:: IO , :: MIME"text/plain" , t:: TrialRatio )
312
330
println (io, " BenchmarkTools.TrialRatio: " )
313
- println (io, " time: " , time (t))
331
+ println (io, " realtime: " , realtime (t))
332
+ println (io, " cputime: " , cputime (t))
314
333
println (io, " gctime: " , gctime (t))
315
334
println (io, " memory: " , memory (t))
316
335
print (io, " allocs: " , allocs (t))
317
336
end
318
337
319
338
@compat function Base. show (io:: IO , :: MIME"text/plain" , t:: TrialJudgement )
320
339
println (io, " BenchmarkTools.TrialJudgement: " )
321
- println (io, " time: " , prettydiff (time (ratio (t))), " => " , time (t), " (" , prettypercent (params (t). time_tolerance), " tolerance)" )
322
- print (io, " memory: " , prettydiff (memory (ratio (t))), " => " , memory (t), " (" , prettypercent (params (t). memory_tolerance), " tolerance)" )
340
+ println (io, " realtime: " , prettydiff (realtime (ratio (t))), " => " , realtime (t), " (" , prettypercent (params (t). time_tolerance), " tolerance)" )
341
+ println (io, " cputime: " , prettydiff (cputime (ratio (t))), " => " , cputime (t), " (" , prettypercent (params (t). time_tolerance), " tolerance)" )
342
+ print (io, " memory: " , prettydiff (memory (ratio (t))), " => " , memory (t), " (" , prettypercent (params (t). memory_tolerance), " tolerance)" )
323
343
end
0 commit comments