@@ -351,63 +351,71 @@ _percentile() = 99 # to tweak this live, TODO remove
351
351
function Base. show (io:: IO , :: MIME"text/plain" , t:: Trial )
352
352
353
353
pad = get (io, :pad , " " )
354
+ padcolor = :light_black
354
355
355
356
showpercentile = _percentile ()
356
357
357
358
perm = sortperm (t. times)
358
359
times = t. times[perm]
359
360
gctimes = t. gctimes[perm]
360
361
361
- if length (t) > 1
362
- med = median (t)
363
- avg = mean (t)
364
- min = minimum (t)
365
- max = maximum (t)
366
- q99 = quantile (t, showpercentile/ 100 )
367
-
368
- mintime = prettytime (time (min))
369
- medtime = prettytime (time (med))
370
- avgtime = prettytime (time (avg))
371
- q99time = prettytime (time (q99))
372
-
373
- # Mean GC time is just that; then we take the percentage of the mean time
374
- avggctime, avegcpercent = prettytime (mean (gctimes)), prettypercent (mean (gctimes) / mean (times))
375
- q99gctime = prettytime (quantile (gctimes, showpercentile/ 100 ))
376
- # Maximum GC time has a percentage which is of the same run, not necc. the longest run
377
- _t, _i = findmax (gctimes)
378
- maxgctime, maxgcpercent = prettytime (_t), prettypercent (_t / times[_i])
379
-
380
- memorystr = prettymemory (memory (min))
381
- allocsstr = prettycount (allocs (min)) * (allocs (min)== 1 ? " allocation" : " allocations" )
382
- elseif length (t) == 1
383
- # TODO update this!
384
-
385
- print (io, pad, " Single result which took " )
386
- printstyled (io, prettytime (times[1 ]); color= :light_blue )
387
- print (io, " (" , prettypercent (gctimes[1 ]/ times[1 ]), " GC) " )
388
- print (io, " to evaluate,\n " )
389
- print (io, pad, " with a memory estimate of " )
390
- printstyled (io, prettymemory (t. memory[1 ]); color= :yellow )
391
- print (io, " , over " )
392
- printstyled (io, t. allocs[1 ]; color= :yellow )
393
- print (io, " allocations." )
362
+ if length (t) == 0
363
+ print (io, " BenchmarkTools.Trial: 0 samples" )
394
364
return
395
- else
396
- print (io, pad, " No results." )
365
+ elseif length (t) == 1
366
+ println (io, " BenchmarkTools.Trial:" )
367
+ # Time
368
+ print (io, pad, " │ Only 1 sample: " )
369
+ printstyled (io, prettytime (times[1 ]); color= :green )
370
+
371
+ # Memory
372
+ println (io)
373
+ print (io, pad, " │ " , prettycount (t. allocs[1 ]), " allocation" , t. allocs[1 ]== 1 ? " " : " s" )
374
+ if t. allocs[1 ] > 0
375
+ print (io, " , " , prettymemory (t. memory[1 ]))
376
+ end
377
+
378
+ # GC time
379
+ if t. gctimes[1 ] > 0
380
+ println (io)
381
+ print (io, pad, " │ GC time: " , prettytime (t. gctimes[1 ]))
382
+ printstyled (io, " (" , prettypercent (t. gctimes[1 ] / t. times[1 ])," )" ; color= :green )
383
+ end
397
384
return
398
- end
385
+ end # done with trivial cases.
399
386
400
- # New block
401
- # println(io, "┌ BenchmarkTools.Trial:")
402
- println (io, " BenchmarkTools.Trial:" )
387
+ med = median (t)
388
+ avg = mean (t)
389
+ min = minimum (t)
390
+ max = maximum (t)
391
+ q99 = quantile (t, showpercentile/ 100 )
403
392
404
- print (io, pad, " │ " )
393
+ mintime = prettytime (time (min))
394
+ medtime = prettytime (time (med))
395
+ avgtime = prettytime (time (avg))
396
+ q99time = prettytime (time (q99))
397
+
398
+ # Mean GC time is just that; then we take the percentage of the mean time
399
+ avggctime, avegcpercent = prettytime (mean (gctimes)), prettypercent (mean (gctimes) / mean (times))
400
+ q99gctime = prettytime (quantile (gctimes, showpercentile/ 100 ))
401
+ # Maximum GC time has a percentage which is of the same run, not necc. the longest run
402
+ _t, _i = findmax (gctimes)
403
+ maxgctime, maxgcpercent = prettytime (_t), prettypercent (_t / times[_i])
404
+
405
+ memorystr = prettymemory (memory (min))
406
+ allocsstr = prettycount (allocs (min)) * (allocs (min)== 1 ? " allocation" : " allocations" )
407
+
408
+ # Main text block:
409
+
410
+ printstyled (io, " BenchmarkTools.Trial:\n " ; color= padcolor)
411
+
412
+ printstyled (io, pad, " │ " ; color= padcolor)
405
413
printstyled (io, " min " ; color= :default )
406
414
printstyled (io, mintime; color= :default , bold= true )
407
415
print (io, " , " )
408
- printstyled (io, " median " ; color= :light_blue )
409
- printstyled (io, medtime; color= :light_blue , bold= true )
410
- printstyled (io, " (½)" ; color= :light_blue )
416
+ printstyled (io, " median " ; color= :blue )
417
+ printstyled (io, medtime; color= :blue , bold= true )
418
+ printstyled (io, " (½)" ; color= :blue )
411
419
print (io, " , " )
412
420
printstyled (io, " mean " ; color= :green )
413
421
printstyled (io, avgtime; color= :green , bold= true )
@@ -417,21 +425,20 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
417
425
printstyled (q99time; bold= true )
418
426
println (io)
419
427
420
- print (io, pad, " │ " , allocsstr)
428
+ printstyled (io, pad, " │ " ; color= padcolor)
429
+ print (io, allocsstr)
421
430
if allocs (min) != 0
422
431
println (io, " , " , memorystr)
423
432
else
424
433
println (io)
425
434
end
426
435
if ! all (iszero, gctimes)
427
- print (io, pad, " │ " , " GC time: mean " , avggctime)
436
+ printstyled (io, pad, " │ " ; color= padcolor)
437
+ print (io, " GC time: mean " , avggctime)
428
438
printstyled (io, " (" , avegcpercent, " )" ; color= :green )
429
439
println (io, " , max " , maxgctime, " (" , maxgcpercent, " )" )
430
440
end
431
441
432
- print (io, pad, " │ " , prettycount (length (t)), " sample" , if length (t) > 1 " s" else " " end ,
433
- " , each " , prettycount (t. params. evals), " evaluation" , if t. params. evals > 1 " s" else " " end , " :" )
434
-
435
442
# Histogram
436
443
437
444
# Axis ends at this quantile, same as displayed time, ideally:
@@ -466,26 +473,28 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
466
473
end
467
474
468
475
# Above the histogram bars, print markers for special ones:
469
- print (io, " \n " , pad, " │ " )
476
+ # println(io)
477
+ printstyled (io, pad, " │ " ; color= padcolor)
470
478
for i in axes (hist, 2 )
471
479
if i == avgpos
472
480
printstyled (io, " *" , color= :green , bold= true ) # or μ, or t̄?
473
481
elseif i == medpos || (medpos== avgpos && i== medpos- 1 )
474
482
# marker for "median" is moved one to the left if they collide
475
- printstyled (io, " ½" , color= :light_blue ) # sadly "㊿" is often double wide. ½, |, ‖, ↓ maybe?
483
+ printstyled (io, " ½" , color= :blue ) # sadly "㊿" is often double wide. ½, |, ‖, ↓ maybe?
476
484
else
477
485
print (io, " " )
478
486
end
479
487
end
480
488
481
489
for r in axes (hist, 1 )
482
- print (io, " \n " , pad, " │ " )
490
+ println (io)
491
+ printstyled (io, pad, " │ " ; color= padcolor)
483
492
for (i, bar) in enumerate (view (hist, r, :))
484
493
color = :default
485
494
if i == avgpos
486
495
color = :green
487
496
elseif i == medpos # if the bars co-incide, colour the mean? matches labels
488
- color = :light_blue
497
+ color = :blue
489
498
elseif bins[i] == 0
490
499
color = :light_black
491
500
end
@@ -496,12 +505,16 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
496
505
remtrailingzeros (timestr) = replace (timestr, r" \. ?0+ " => " " )
497
506
minhisttime, maxhisttime = remtrailingzeros .(prettytime .(round .([histmin, histmax], sigdigits= 3 )))
498
507
499
- print (io, " \n " , pad, " └ " , minhisttime)
508
+ println (io)
509
+ printstyled (io, pad, " └ " ; color= padcolor)
510
+ print (io, minhisttime)
500
511
# Caption is only printed if logbins has been selected:
501
- caption = logbins ? " log(counts) by time" : " "
512
+ caption = string (prettycount (length (t)), " sample" , if length (t) > 1 " s" else " " end ,
513
+ " , each " , prettycount (t. params. evals), " evaluation" , if t. params. evals > 1 " s" else " " end )
514
+ caption = logbins ? (" log(counts) from " * caption) : caption
502
515
printstyled (io, " " ^ ((histwidth - length (caption)) ÷ 2 - length (minhisttime)), caption; color= :light_black )
503
516
print (io, lpad (maxhisttime, ceil (Int, (histwidth - length (caption)) / 2 ) - 1 ), " " )
504
- printstyled (io, " +" )
517
+ print (io, " +" )
505
518
end
506
519
507
520
# These two functions allow endpoints 6, 7, 8, 10, 15, 20, 30, 40, ... perhaps too coarse?
0 commit comments