@@ -225,6 +225,17 @@ isimprovement(t::TrialJudgement) = time(t) == :improvement || memory(t) == :impr
225
225
isregression (t:: TrialJudgement ) = time (t) == :regression || memory (t) == :regression
226
226
isinvariant (t:: TrialJudgement ) = time (t) == :invariant && memory (t) == :invariant
227
227
228
+ const colormap = (
229
+ regression = :red ,
230
+ improvement = :green ,
231
+ invariant = :normal ,
232
+ )
233
+
234
+ printtimejudge (io, t:: TrialJudgement ) =
235
+ printstyled (io, time (t); color= colormap[time (t)])
236
+ printmemoryjudge (io, t:: TrialJudgement ) =
237
+ printstyled (io, memory (t); color= colormap[memory (t)])
238
+
228
239
# ##################
229
240
# Pretty Printing #
230
241
# ##################
@@ -262,12 +273,40 @@ function prettymemory(b)
262
273
return string (@sprintf (" %.2f" , value), " " , units)
263
274
end
264
275
265
- Base. summary (io:: IO , t:: Trial ) = print (io, " Trial(" , prettytime (time (t)), " )" )
266
- Base. summary (io:: IO , t:: TrialEstimate ) = print (io, " TrialEstimate(" , prettytime (time (t)), " )" )
267
- Base. summary (io:: IO , t:: TrialRatio ) = print (io, " TrialRatio(" , prettypercent (time (t)), " )" )
268
- Base. summary (io:: IO , t:: TrialJudgement ) = print (io, " TrialJudgement(" , prettydiff (time (ratio (t))), " => " , time (t), " )" )
276
+ function withtypename (f, io, t)
277
+ needtype = get (io, :typeinfo , Nothing) != = typeof (t)
278
+ if needtype
279
+ print (io, nameof (typeof (t)), ' (' )
280
+ end
281
+ f ()
282
+ if needtype
283
+ print (io, ' )' )
284
+ end
285
+ end
286
+
287
+ _summary (io, t, args... ) = withtypename (() -> print (io, args... ), io, t)
288
+
289
+ Base. summary (io:: IO , t:: Trial ) = _summary (io, t, prettytime (time (t)))
290
+ Base. summary (io:: IO , t:: TrialEstimate ) = _summary (io, t, prettytime (time (t)))
291
+ Base. summary (io:: IO , t:: TrialRatio ) = _summary (io, t, prettypercent (time (t)))
292
+ Base. summary (io:: IO , t:: TrialJudgement ) = withtypename (io, t) do
293
+ print (io, prettydiff (time (ratio (t))), " => " )
294
+ printtimejudge (io, t)
295
+ end
296
+
297
+ _show (io, t) =
298
+ if get (io, :compact , true )
299
+ summary (io, t)
300
+ else
301
+ show (io, MIME " text/plain" (), t)
302
+ end
303
+
304
+ Base. show (io:: IO , t:: Trial ) = _show (io, t)
305
+ Base. show (io:: IO , t:: TrialEstimate ) = _show (io, t)
306
+ Base. show (io:: IO , t:: TrialRatio ) = _show (io, t)
307
+ Base. show (io:: IO , t:: TrialJudgement ) = _show (io, t)
269
308
270
- function Base. show (io:: IO , t:: Trial )
309
+ function Base. show (io:: IO , :: MIME"text/plain" , t:: Trial )
271
310
if length (t) > 0
272
311
min = minimum (t)
273
312
max = maximum (t)
@@ -301,7 +340,7 @@ function Base.show(io::IO, t::Trial)
301
340
print (io, pad, " evals/sample: " , t. params. evals)
302
341
end
303
342
304
- function Base. show (io:: IO , t:: TrialEstimate )
343
+ function Base. show (io:: IO , :: MIME"text/plain" , t:: TrialEstimate )
305
344
println (io, " BenchmarkTools.TrialEstimate: " )
306
345
pad = get (io, :pad , " " )
307
346
println (io, pad, " time: " , prettytime (time (t)))
@@ -310,7 +349,7 @@ function Base.show(io::IO, t::TrialEstimate)
310
349
print (io, pad, " allocs: " , allocs (t))
311
350
end
312
351
313
- function Base. show (io:: IO , t:: TrialRatio )
352
+ function Base. show (io:: IO , :: MIME"text/plain" , t:: TrialRatio )
314
353
println (io, " BenchmarkTools.TrialRatio: " )
315
354
pad = get (io, :pad , " " )
316
355
println (io, pad, " time: " , time (t))
@@ -319,9 +358,13 @@ function Base.show(io::IO, t::TrialRatio)
319
358
print (io, pad, " allocs: " , allocs (t))
320
359
end
321
360
322
- function Base. show (io:: IO , t:: TrialJudgement )
361
+ function Base. show (io:: IO , :: MIME"text/plain" , t:: TrialJudgement )
323
362
println (io, " BenchmarkTools.TrialJudgement: " )
324
363
pad = get (io, :pad , " " )
325
- println (io, pad, " time: " , prettydiff (time (ratio (t))), " => " , time (t), " (" , prettypercent (params (t). time_tolerance), " tolerance)" )
326
- print (io, pad, " memory: " , prettydiff (memory (ratio (t))), " => " , memory (t), " (" , prettypercent (params (t). memory_tolerance), " tolerance)" )
364
+ print (io, pad, " time: " , prettydiff (time (ratio (t))), " => " )
365
+ printtimejudge (io, t)
366
+ println (io, " (" , prettypercent (params (t). time_tolerance), " tolerance)" )
367
+ print (io, pad, " memory: " , prettydiff (memory (ratio (t))), " => " )
368
+ printmemoryjudge (io, t)
369
+ println (io, " (" , prettypercent (params (t). memory_tolerance), " tolerance)" )
327
370
end
0 commit comments