Skip to content

Commit 0bf19f6

Browse files
committed
wednesday
1 parent ce98c93 commit 0bf19f6

File tree

1 file changed

+68
-55
lines changed

1 file changed

+68
-55
lines changed

src/trials.jl

Lines changed: 68 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -351,63 +351,71 @@ _percentile() = 99 # to tweak this live, TODO remove
351351
function Base.show(io::IO, ::MIME"text/plain", t::Trial)
352352

353353
pad = get(io, :pad, "")
354+
padcolor = :light_black
354355

355356
showpercentile = _percentile()
356357

357358
perm = sortperm(t.times)
358359
times = t.times[perm]
359360
gctimes = t.gctimes[perm]
360361

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")
394364
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
397384
return
398-
end
385+
end # done with trivial cases.
399386

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)
403392

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)
405413
printstyled(io, "min "; color=:default)
406414
printstyled(io, mintime; color=:default, bold=true)
407415
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)
411419
print(io, ", ")
412420
printstyled(io, "mean "; color=:green)
413421
printstyled(io, avgtime; color=:green, bold=true)
@@ -417,21 +425,20 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
417425
printstyled(q99time; bold=true)
418426
println(io)
419427

420-
print(io, pad, "", allocsstr)
428+
printstyled(io, pad, ""; color=padcolor)
429+
print(io, allocsstr)
421430
if allocs(min) != 0
422431
println(io, ", ", memorystr)
423432
else
424433
println(io)
425434
end
426435
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)
428438
printstyled(io, " (", avegcpercent, ")"; color=:green)
429439
println(io, ", max ", maxgctime, " (", maxgcpercent, ")")
430440
end
431441

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-
435442
# Histogram
436443

437444
# Axis ends at this quantile, same as displayed time, ideally:
@@ -466,26 +473,28 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
466473
end
467474

468475
# Above the histogram bars, print markers for special ones:
469-
print(io, "\n", pad, "")
476+
# println(io)
477+
printstyled(io, pad, ""; color=padcolor)
470478
for i in axes(hist, 2)
471479
if i == avgpos
472480
printstyled(io, "*", color=:green, bold=true) # or μ, or t̄?
473481
elseif i == medpos || (medpos==avgpos && i==medpos-1)
474482
# 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?
476484
else
477485
print(io, " ")
478486
end
479487
end
480488

481489
for r in axes(hist, 1)
482-
print(io, "\n", pad, "")
490+
println(io)
491+
printstyled(io, pad, ""; color=padcolor)
483492
for (i, bar) in enumerate(view(hist, r, :))
484493
color = :default
485494
if i == avgpos
486495
color = :green
487496
elseif i == medpos # if the bars co-incide, colour the mean? matches labels
488-
color = :light_blue
497+
color = :blue
489498
elseif bins[i] == 0
490499
color = :light_black
491500
end
@@ -496,12 +505,16 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
496505
remtrailingzeros(timestr) = replace(timestr, r"\.?0+ " => " ")
497506
minhisttime, maxhisttime = remtrailingzeros.(prettytime.(round.([histmin, histmax], sigdigits=3)))
498507

499-
print(io, "\n", pad, "", minhisttime)
508+
println(io)
509+
printstyled(io, pad, ""; color=padcolor)
510+
print(io, minhisttime)
500511
# 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
502515
printstyled(io, " " ^ ((histwidth - length(caption)) ÷ 2 - length(minhisttime)), caption; color=:light_black)
503516
print(io, lpad(maxhisttime, ceil(Int, (histwidth - length(caption)) / 2) - 1), " ")
504-
printstyled(io, "+")
517+
print(io, "+")
505518
end
506519

507520
# These two functions allow endpoints 6, 7, 8, 10, 15, 20, 30, 40, ... perhaps too coarse?

0 commit comments

Comments
 (0)