Skip to content

Commit e24de38

Browse files
committed
add show method for Vector{Trial}
1 parent f4b6678 commit e24de38

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

src/trials.jl

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,7 @@ Base.show(io::IO, t::TrialJudgement) = _show(io, t)
356356

357357
function Base.show(io::IO, ::MIME"text/plain", t::Trial)
358358
pad = get(io, :pad, "")
359+
histnumber = get(io, :histnumber, "") # for Vector{Trial} printing
359360

360361
boxcolor = :light_black
361362
boxspace = " "
@@ -382,10 +383,10 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
382383
)
383384

384385
if length(t) == 0
385-
print(io, modulestr, "Trial: 0 samples")
386+
print(io, modulestr, "Trial$histnumber: 0 samples")
386387
return
387388
elseif length(t) == 1
388-
printstyled(io, "", modulestr, "Trial:\n"; color=boxcolor)
389+
printstyled(io, "", modulestr, "Trial$histnumber:\n"; color=boxcolor)
389390

390391
# Time
391392
printstyled(io, pad, "", boxspace; color=boxcolor)
@@ -417,7 +418,7 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
417418

418419
# Main text block
419420

420-
printstyled(io, "", modulestr, "Trial:\n"; color=boxcolor)
421+
printstyled(io, "", modulestr, "Trial$histnumber:\n"; color=boxcolor)
421422

422423
printstyled(io, pad, "", boxspace; color=boxcolor)
423424
printstyled(io, "min "; color=:default)
@@ -558,6 +559,27 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
558559
# printstyled(io, "●", color=:light_black) # other options "⋯" "¹⁰⁰"
559560
end
560561

562+
function Base.show(io::IO, m::MIME"text/plain", vt::AbstractVector{<:Trial})
563+
bounds = map(vt) do t
564+
# compute these exactly as in individual show methods:
565+
mintime = minimum(t.times)
566+
avgtime = mean(t.times)
567+
quantime = quantile(t.times, 99/100)
568+
lo = hist_round_low(t.times, mintime, avgtime)
569+
hi = hist_round_high(t.times, avgtime, quantime)
570+
(lo, hi)
571+
end
572+
histmin = get(io, :histmin, minimum(first, bounds))
573+
histmax = get(io, :histmax, maximum(last, bounds))
574+
ioc = IOContext(io, :histmin => histmin, :histmax => histmax)
575+
576+
print(io, summary(vt), ":")
577+
for (i,t) in pairs(vt)
578+
println(io)
579+
show(IOContext(ioc, :histnumber => " [$i]"), m, t)
580+
end
581+
end
582+
561583
function Base.show(io::IO, ::MIME"text/plain", t::TrialEstimate)
562584
println(io, "BenchmarkTools.TrialEstimate: ")
563585
pad = get(io, :pad, "")

0 commit comments

Comments
 (0)