Skip to content

Commit 4204e47

Browse files
committed
tests etc
1 parent 1c6c164 commit 4204e47

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

src/trials.jl

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -323,12 +323,13 @@ function asciihist(bins, height=1)
323323
end
324324

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

334335
_summary(io, t, args...) = withtypename(() -> print(io, args...), io, t)

test/TrialsTests.jl

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -237,32 +237,31 @@ else
237237

238238
end
239239

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

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

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

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

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

261-
@test sprint(show, t001) == "Trial(3.142 ms)"
262-
@test sprint(show, t003) == "Trial(0.010 ns)"
263-
@test sprint(show, "text/plain", [t001, t003]) == "2-element Vector{BenchmarkTools.Trial}:\n 3.142 ms\n 0.010 ns"
264-
@test_skip sprint(show, "text/plain", [t0]) == "1-element Vector{BenchmarkTools.Trial}:\n ??"
265-
266265
t123 = BenchmarkTools.Trial(BenchmarkTools.Parameters(), [1,2,3.], [0,0,0.], 0, 0)
267266
s123 = sprint(show, "text/plain", t123)
268267
@test contains(s123, "min 1.000 ns, median 2.000 ns, mean 2.000 ns")
@@ -282,6 +281,12 @@ s456 = sprint(show, "text/plain", t456)
282281
@test contains(s456, "│ █▁▁▁▁▁▁▁")
283282
@test contains(s456, "└ 100 ns ") # box closing + left endpoint without decimals
284283

284+
# Compact show & arrays of Trials
285+
@test sprint(show, t001) == "Trial(3.142 ms)"
286+
@test sprint(show, t003) == "Trial(0.010 ns)"
287+
@test sprint(show, "text/plain", [t001, t003]) == "2-element Vector{BenchmarkTools.Trial}:\n 3.142 ms\n 0.010 ns"
288+
@test_skip sprint(show, "text/plain", [t0]) == "1-element Vector{BenchmarkTools.Trial}:\n ??"
289+
285290
#=
286291
287292
# Some visual histogram checks, in which mean/median should highlight a bar, or not:

0 commit comments

Comments
 (0)