Skip to content

Commit e4a02bc

Browse files
committed
Make sure times are sorted in the at-benchmark histogram
1 parent 540fa91 commit e4a02bc

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name = "BenchmarkTools"
22
uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
3-
version = "1.1.3"
3+
version = "1.1.4"
44

55
[deps]
66
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"

src/trials.jl

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,10 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
344344
print(io, "BenchmarkTools.Trial: ", length(t), " sample", if length(t) > 1 "s" else "" end,
345345
" with ", t.params.evals, " evaluation", if t.params.evals > 1 "s" else "" end ,".\n")
346346

347+
perm = sortperm(t.times)
348+
times = t.times[perm]
349+
gctimes = t.gctimes[perm]
350+
347351
if length(t) > 1
348352
med = median(t)
349353
avg = mean(t)
@@ -353,16 +357,16 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
353357

354358
medtime, medgc = prettytime(time(med)), prettypercent(gcratio(med))
355359
avgtime, avggc = prettytime(time(avg)), prettypercent(gcratio(avg))
356-
stdtime, stdgc = prettytime(time(std)), prettypercent(Statistics.std(t.gctimes ./ t.times))
360+
stdtime, stdgc = prettytime(time(std)), prettypercent(Statistics.std(gctimes ./ times))
357361
mintime, mingc = prettytime(time(min)), prettypercent(gcratio(min))
358362
maxtime, maxgc = prettytime(time(max)), prettypercent(gcratio(max))
359363

360364
memorystr = string(prettymemory(memory(min)))
361365
allocsstr = string(allocs(min))
362366
elseif length(t) == 1
363367
print(io, pad, " Single result which took ")
364-
printstyled(io, prettytime(t.times[1]); color=:blue)
365-
print(io, " (", prettypercent(t.gctimes[1]/t.times[1]), " GC) ")
368+
printstyled(io, prettytime(times[1]); color=:blue)
369+
print(io, " (", prettypercent(gctimes[1]/times[1]), " GC) ")
366370
print(io, "to evaluate,\n")
367371
print(io, pad, " with a memory estimate of ")
368372
printstyled(io, prettymemory(t.memory[1]); color=:yellow)
@@ -435,11 +439,11 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
435439
histheight = 2
436440
histwidth = 42 + lmaxtimewidth + rmaxtimewidth
437441

438-
histtimes = t.times[1:round(Int, histquantile*end)]
442+
histtimes = times[1:round(Int, histquantile*end)]
439443
bins, logbins = bindata(histtimes, histwidth - 1), false
440-
append!(bins, [1, floor((1-histquantile) * length(t.times))])
444+
append!(bins, [1, floor((1-histquantile) * length(times))])
441445
# if median size of (bins with >10% average data/bin) is less than 5% of max bin size, log the bin sizes
442-
if median(filter(b -> b > 0.1 * length(t.times) / histwidth, bins)) / maximum(bins) < 0.05
446+
if median(filter(b -> b > 0.1 * length(times) / histwidth, bins)) / maximum(bins) < 0.05
443447
bins, logbins = log.(1 .+ bins), true
444448
end
445449
hist = asciihist(bins, histheight)
@@ -448,8 +452,8 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
448452

449453
delta1 = (histtimes[end] - histtimes[1]) / (histwidth - 1)
450454
if delta1 > 0
451-
medpos = 1 + round(Int, (histtimes[length(t.times) ÷ 2] - histtimes[1]) / delta1)
452-
avgpos = 1 + round(Int, (mean(t.times) - histtimes[1]) / delta1)
455+
medpos = 1 + round(Int, (histtimes[length(times) ÷ 2] - histtimes[1]) / delta1)
456+
avgpos = 1 + round(Int, (mean(times) - histtimes[1]) / delta1)
453457
else
454458
medpos, avgpos = 1, 1
455459
end

0 commit comments

Comments
 (0)