Skip to content

Commit

Permalink
tests etc
Browse files Browse the repository at this point in the history
  • Loading branch information
mcabbott committed Oct 1, 2021
1 parent 31f2c94 commit e9648d4
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
9 changes: 5 additions & 4 deletions src/trials.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,12 +323,13 @@ function asciihist(bins, height=1)
end

function hist_round_low(times, lo=minimum(times), av=mean(times))
_min = min(lo, av / 1.03) # demand low edge 3% from mean, or further
return round(_min, RoundDown; sigdigits = 2)
av < 0.1 && return 0.0 # stop at 0, not 0.01 ns, in trivial cases
raw = min(lo, av / 1.03) # demand low edge 3% from mean, or further
return round(raw, RoundDown; sigdigits = 2)
end
function hist_round_high(times, av=mean(times), hi=quantile(times, 0.99))
_max = max(1, hi, 1.03 * av) # demand high edge 3% above mean, and at least 1ns
return round(_max, RoundUp; sigdigits = 2)
raw = max(1, hi, 1.03 * av) # demand high edge 3% above mean, and at least 1ns
return round(raw, RoundUp; sigdigits = 2)
end

_summary(io, t, args...) = withtypename(() -> print(io, args...), io, t)
Expand Down
15 changes: 10 additions & 5 deletions test/TrialsTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,32 +237,31 @@ else

end

# Trial with 0 samples
t0 = BenchmarkTools.Trial(BenchmarkTools.Parameters(), [], [], 0, 0)
@test sprint(show, "text/plain", t0) == "Trial: 0 samples"

# Trial with 1 sample
t001 = BenchmarkTools.Trial(BenchmarkTools.Parameters(), [pi * 10^6], [0], 0, 0)
s001 = sprint(show, "text/plain", t001)
@test contains(s001, "┌ Trial:") # box starting at the type
@test contains(s001, "│ time 3.142 ms")
@test contains(s001, "│ 0 allocations\n") # doesn't print 0 bytes after this
@test contains(s001, "└ 1 sample, with 1 evaluation")

# Histogram utils
@test BenchmarkTools.asciihist([1,2,3]) == ['' '' '']
@test BenchmarkTools.asciihist([1,2,0,3], 2) == [' ' '' ' ' ''; '' '' '' '']

@test BenchmarkTools.histogram_bindata([1.1, 3.1, 99], 1:3) == [1,0,2]
@test BenchmarkTools.histogram_bindata([1.1, -99, 3.1], 1:3.0) == [1,0,1]

# Trials with several samples
t003 = BenchmarkTools.Trial(BenchmarkTools.Parameters(), [0.01, 0.02, 0.04], [0,0,0], 0, 0)
s003 = sprint(show, "text/plain", t003)
@test contains(s003, " 1 ns +") # right limit is 1ns
@test contains(s003, "min 0.010 ns, median 0.020 ns, mean 0.023 ns, 99ᵗʰ 0.040 ns")

@test sprint(show, t001) == "Trial(3.142 ms)"
@test sprint(show, t003) == "Trial(0.010 ns)"
@test sprint(show, "text/plain", [t001, t003]) == "2-element Vector{BenchmarkTools.Trial}:\n 3.142 ms\n 0.010 ns"
@test_skip sprint(show, "text/plain", [t0]) == "1-element Vector{BenchmarkTools.Trial}:\n ??"

t123 = BenchmarkTools.Trial(BenchmarkTools.Parameters(), [1,2,3.], [0,0,0.], 0, 0)
s123 = sprint(show, "text/plain", t123)
@test contains(s123, "min 1.000 ns, median 2.000 ns, mean 2.000 ns")
Expand All @@ -282,6 +281,12 @@ s456 = sprint(show, "text/plain", t456)
@test contains(s456, "│ █▁▁▁▁▁▁▁")
@test contains(s456, "└ 100 ns ") # box closing + left endpoint without decimals

# Compact show & arrays of Trials
@test sprint(show, t001) == "Trial(3.142 ms)"
@test sprint(show, t003) == "Trial(0.010 ns)"
@test sprint(show, "text/plain", [t001, t003]) == "2-element Vector{BenchmarkTools.Trial}:\n 3.142 ms\n 0.010 ns"
@test_skip sprint(show, "text/plain", [t0]) == "1-element Vector{BenchmarkTools.Trial}:\n ??"

#=
# Some visual histogram checks, in which mean/median should highlight a bar, or not:
Expand Down

0 comments on commit e9648d4

Please sign in to comment.