Skip to content

Commit 0270da0

Browse files
committed
Add :logbins to settings
1 parent 5d74ad0 commit 0270da0

File tree

3 files changed

+23
-16
lines changed

3 files changed

+23
-16
lines changed

docs/src/manual.md

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -901,33 +901,37 @@ For comparing two or more benchmarks against one another, you can manually speci
901901
`IOContext` to set `:histmin` and `:histmax`:
902902

903903
```julia
904-
julia> io = IOContext(stdout, :histmin=>0.5, :histmax=>8)
904+
julia> io = IOContext(stdout, :histmin=>0.5, :histmax=>8, :logbins=>true)
905905
IOContext(Base.TTY(RawFD(13) open, 0 bytes waiting))
906906

907-
julia> b = @benchmark x^3 setup=(x = rand()); show(io, MIME("text/plain"), b)
907+
julia> b = @benchmark x^3 setup=(x = rand()); show(io, MIME("text/plain"), b)
908908
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
909-
Range (min max): 1.239 ns 28.036 ns ┊ GC (min max): 0.00% 0.00%
910-
Time (median): 1.258 ns ┊ GC (median): 0.00%
911-
Time (mean ± σ): 1.277 ns ± 0.593 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
909+
Range (min max): 1.239 ns 31.433 ns ┊ GC (min max): 0.00% 0.00%
910+
Time (median): 1.244 ns ┊ GC (median): 0.00%
911+
Time (mean ± σ): 1.266 ns ± 0.611 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
912912

913-
▁ ▁
914-
▁▁▁▁▁██▆▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁
913+
914+
▁▁▁▁▁█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
915915
0.5 ns Histogram: log(frequency) by time 8 ns <
916916

917917
Memory estimate: 0 bytes, allocs estimate: 0.
918918
julia> b = @benchmark x^3.0 setup=(x = rand()); show(io, MIME("text/plain"), b)
919919
BenchmarkTools.Trial: 10000 samples with 1000 evaluations.
920-
Range (min max): 5.399 ns 35.552 ns ┊ GC (min max): 0.00% 0.00%
921-
Time (median): 5.422 ns ┊ GC (median): 0.00%
922-
Time (mean ± σ): 5.510 ns ± 1.291 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
920+
Range (min max): 5.636 ns 38.756 ns ┊ GC (min max): 0.00% 0.00%
921+
Time (median): 5.662 ns ┊ GC (median): 0.00%
922+
Time (mean ± σ): 5.767 ns ± 1.384 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
923923

924-
925-
▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▅█▂▂▂▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁ ▂
926-
0.5 ns Histogram: frequency by time 8 ns <
924+
█▆ ▂ ▁
925+
▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁███▄▄▃█▁▁▁▁▁▁▁▁▁▁▁▁
926+
0.5 ns Histogram: log(frequency) by time 8 ns <
927927

928928
Memory estimate: 0 bytes, allocs estimate: 0.
929+
929930
```
930931

932+
Set `:logbins` to `true` or `false` to ensure that all use the same vertical scaling (log frequency or frequency).
933+
934+
931935
The `Trial` object can be visualized using the `BenchmarkPlots` package:
932936

933937
```julia

src/trials.jl

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -442,11 +442,14 @@ function Base.show(io::IO, ::MIME"text/plain", t::Trial)
442442
histtimes = times[1:round(Int, histquantile*end)]
443443
histmin = get(io, :histmin, first(histtimes))
444444
histmax = get(io, :histmax, last(histtimes))
445-
bins, logbins = bindata(histtimes, histwidth - 1, histmin, histmax), false
445+
logbins = get(io, :logbins, nothing)
446+
bins = bindata(histtimes, histwidth - 1, histmin, histmax)
446447
append!(bins, [1, floor((1-histquantile) * length(times))])
447448
# if median size of (bins with >10% average data/bin) is less than 5% of max bin size, log the bin sizes
448-
if median(filter(b -> b > 0.1 * length(times) / histwidth, bins)) / maximum(bins) < 0.05
449+
if (logbins === nothing || logbins === true) && median(filter(b -> b > 0.1 * length(times) / histwidth, bins)) / maximum(bins) < 0.05
449450
bins, logbins = log.(1 .+ bins), true
451+
elseif logbins === nothing
452+
logbins = false
450453
end
451454
hist = asciihist(bins, histheight)
452455
hist[:,end-1] .= ' '

test/ExecutionTests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ tune!(b)
136136
@benchmark(output=sin(x), setup=(x=1.0; output=0.0), teardown=(@test output == sin(x)))
137137

138138
io = IOBuffer()
139-
ioctx = IOContext(io, :histmin=>0.5, :histmax=>8)
139+
ioctx = IOContext(io, :histmin=>0.5, :histmax=>8, :logbins=>false)
140140
b = @benchmark x^3 setup=(x = rand()); show(ioctx, MIME("text/plain"), b)
141141
b = @benchmark x^3.0 setup=(x = rand()); show(ioctx, MIME("text/plain"), b)
142142
str = String(take!(io))

0 commit comments

Comments
 (0)