From e24de3828e00ece8640cd95ca77f4f7d922e85de Mon Sep 17 00:00:00 2001 From: Michael Abbott <32575566+mcabbott@users.noreply.github.com> Date: Wed, 23 Mar 2022 23:59:09 -0400 Subject: [PATCH] add show method for Vector{Trial} --- src/trials.jl | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) diff --git a/src/trials.jl b/src/trials.jl index 1624a7c7..a0abd8d6 100644 --- a/src/trials.jl +++ b/src/trials.jl @@ -356,6 +356,7 @@ Base.show(io::IO, t::TrialJudgement) = _show(io, t) function Base.show(io::IO, ::MIME"text/plain", t::Trial) pad = get(io, :pad, "") + histnumber = get(io, :histnumber, "") # for Vector{Trial} printing boxcolor = :light_black boxspace = " " @@ -382,10 +383,10 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial) ) if length(t) == 0 - print(io, modulestr, "Trial: 0 samples") + print(io, modulestr, "Trial$histnumber: 0 samples") return elseif length(t) == 1 - printstyled(io, "┌ ", modulestr, "Trial:\n"; color=boxcolor) + printstyled(io, "┌ ", modulestr, "Trial$histnumber:\n"; color=boxcolor) # Time printstyled(io, pad, "│", boxspace; color=boxcolor) @@ -417,7 +418,7 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial) # Main text block - printstyled(io, "┌ ", modulestr, "Trial:\n"; color=boxcolor) + printstyled(io, "┌ ", modulestr, "Trial$histnumber:\n"; color=boxcolor) printstyled(io, pad, "│", boxspace; color=boxcolor) printstyled(io, "min "; color=:default) @@ -558,6 +559,27 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial) # printstyled(io, "●", color=:light_black) # other options "⋯" "¹⁰⁰" end +function Base.show(io::IO, m::MIME"text/plain", vt::AbstractVector{<:Trial}) + bounds = map(vt) do t + # compute these exactly as in individual show methods: + mintime = minimum(t.times) + avgtime = mean(t.times) + quantime = quantile(t.times, 99/100) + lo = hist_round_low(t.times, mintime, avgtime) + hi = hist_round_high(t.times, avgtime, quantime) + (lo, hi) + end + histmin = get(io, :histmin, minimum(first, bounds)) + histmax = get(io, :histmax, maximum(last, bounds)) + ioc = IOContext(io, :histmin => histmin, :histmax => histmax) + + print(io, summary(vt), ":") + for (i,t) in pairs(vt) + println(io) + show(IOContext(ioc, :histnumber => " [$i]"), m, t) + end +end + function Base.show(io::IO, ::MIME"text/plain", t::TrialEstimate) println(io, "BenchmarkTools.TrialEstimate: ") pad = get(io, :pad, "")