Skip to content

Commit

Permalink
Show trials with 1 sample without error (#234)
Browse files Browse the repository at this point in the history
* Show trials with 1 sample without error

When only a single sample is present, show the info on that one result.
Also use plurals appropriately with sample(s) and evaluation(s).

* Add test for displaying single-sample trial
  • Loading branch information
tecosaur authored Jul 16, 2021
1 parent 3233d3f commit 53d586b
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
41 changes: 27 additions & 14 deletions src/trials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,12 @@ Base.show(io::IO, t::TrialRatio) = _show(io, t)
Base.show(io::IO, t::TrialJudgement) = _show(io, t)

function Base.show(io::IO, ::MIME"text/plain", t::Trial)
if length(t) > 0

pad = get(io, :pad, "")
print(io, "BenchmarkTools.Trial: ", length(t), " sample", if length(t) > 1 "s" else "" end,
" with ", t.params.evals, " evaluation", if t.params.evals > 1 "s" else "" end ,".\n")

if length(t) > 1
med = median(t)
avg = mean(t)
std = Statistics.std(t)
Expand All @@ -354,13 +359,20 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)

memorystr = string(prettymemory(memory(min)))
allocsstr = string(allocs(min))
elseif length(t) == 1
print(io, pad, " Single result which took ")
printstyled(io, prettytime(t.times[1]); color=:blue)
print(io, " (", prettypercent(t.gctimes[1]/t.times[1]), " GC) ")
print(io, "to evaluate,\n")
print(io, pad, " with a memory estimate of ")
printstyled(io, prettymemory(t.memory[1]); color=:yellow)
print(io, ", over ")
printstyled(io, t.allocs[1]; color=:yellow)
print(io, " allocations.")
return
else
medtime, medgc = "N/A", "N/A"
avgtime, avggc = "N/A", "N/A"
stdtime, stdgc = "N/A", "N/A"
mintime, mingc = "N/A", "N/A"
maxtime, maxgc = "N/A", "N/A"
memorystr, allocsstr = "N/A", "N/A"
print(io, pad, " No results.")
return
end

lmaxtimewidth = maximum(length.((medtime, avgtime, mintime)))
Expand All @@ -370,10 +382,7 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)

# Main stats

pad = get(io, :pad, "")
print(io, "BenchmarkTools.Trial: ", length(t), " samples with ", t.params.evals, " evaluations.")

print(io, "\n", pad, " Range ")
print(io, pad, " Range ")
printstyled(io, "("; color=:light_black)
printstyled(io, "min"; color=:cyan, bold=true)
print(io, "")
Expand Down Expand Up @@ -434,12 +443,16 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
bins, logbins = log.(1 .+ bins), true
end
hist = asciihist(bins, histheight)
hist[end,end-1] = ' '
hist[:,end-1] .= ' '
maxbin = maximum(bins)

delta1 = (histtimes[end] - histtimes[1]) / (histwidth - 1)
medpos = 1 + round(Int, (histtimes[length(t.times) ÷ 2] - histtimes[1]) / delta1)
avgpos = 1 + round(Int, (mean(t.times) - histtimes[1]) / delta1)
if delta1 > 0
medpos = 1 + round(Int, (histtimes[length(t.times) ÷ 2] - histtimes[1]) / delta1)
avgpos = 1 + round(Int, (mean(t.times) - histtimes[1]) / delta1)
else
medpos, avgpos = 1, 1
end

print(io, "\n")
for histrow in eachrow(hist)
Expand Down
3 changes: 3 additions & 0 deletions test/TrialsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,9 @@ BenchmarkTools.TrialEstimate:

@test sprint(show, [ta, tb]) == "BenchmarkTools.TrialEstimate[0.490 ns, 1.000 ns]"

trial1sample = BenchmarkTools.Trial(BenchmarkTools.Parameters(), [1], [1], 1, 1)
@test try display(trial1sample); true catch e false end

@static if VERSION < v"1.6-"

@test sprint(show, "text/plain", [ta, tb]) == """
Expand Down

0 comments on commit 53d586b

Please sign in to comment.