@@ -198,6 +198,10 @@ tj_r_2 = judge(tr; time_tolerance = 2.0, memory_tolerance = 2.0)
198
198
@test BenchmarkTools. prettymemory (1073741823 ) == " 1024.00 MiB"
199
199
@test BenchmarkTools. prettymemory (1073741824 ) == " 1.00 GiB"
200
200
201
+ @test BenchmarkTools. prettycount (10 ) == " 10"
202
+ @test BenchmarkTools. prettycount (1023 ) == " 1_023"
203
+ @test BenchmarkTools. prettycount (40560789 ) == " 40_560_789"
204
+
201
205
@test sprint (show, " text/plain" , ta) == sprint (show, ta; context= :compact => false ) == """
202
206
BenchmarkTools.TrialEstimate:
203
207
time: 0.490 ns
@@ -233,17 +237,87 @@ else
233
237
234
238
end
235
239
236
- trial = BenchmarkTools. Trial (BenchmarkTools. Parameters (), [1.0 , 1.01 ], [0.0 , 0.0 ], 0 , 0 )
237
- @test sprint (show, " text/plain" , trial) == """
238
- BenchmarkTools.Trial: 2 samples with 1 evaluation.
239
- Range (min … max): 1.000 ns … 1.010 ns ┊ GC (min … max): 0.00% … 0.00%
240
- Time (median): 1.005 ns ┊ GC (median): 0.00%
241
- Time (mean ± σ): 1.005 ns ± 0.007 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
240
+ t0 = BenchmarkTools. Trial (BenchmarkTools. Parameters (), [], [], 0 , 0 )
241
+ @test sprint (show, " text/plain" , t0) == " Trial: 0 samples"
242
+
243
+ t001 = BenchmarkTools. Trial (BenchmarkTools. Parameters (), [pi * 10 ^ 6 ], [0 ], 0 , 0 )
244
+ s001 = sprint (show, " text/plain" , t001)
245
+ @test contains (s001, " ┌ Trial:" ) # box starting at the type
246
+ @test contains (s001, " │ time 3.142 ms" )
247
+ @test contains (s001, " │ 0 allocations\n " ) # doesn't print 0 bytes after this
248
+ @test contains (s001, " └ 1 sample, with 1 evaluation" )
249
+
250
+ @test BenchmarkTools. asciihist ([1 ,2 ,3 ]) == [' ▃' ' ▆' ' █' ]
251
+ @test BenchmarkTools. asciihist ([1 ,2 ,0 ,3 ], 2 ) == [' ' ' ▃' ' ' ' █' ; ' ▇' ' █' ' ▁' ' █' ]
252
+
253
+ @test BenchmarkTools. histogram_bindata ([1.1 , 3.1 , 99 ], 1 : 3 ) == [1 ,0 ,2 ]
254
+ @test BenchmarkTools. histogram_bindata ([1.1 , - 99 , 3.1 ], 1 : 3.0 ) == [1 ,0 ,1 ]
255
+
256
+ t003 = BenchmarkTools. Trial (BenchmarkTools. Parameters (), [0.01 , 0.02 , 0.04 ], [0 ,0 ,0 ], 0 , 0 )
257
+ s003 = sprint (show, " text/plain" , t003)
258
+ @test contains (s003, " 1 ns +" ) # right limit is 1ns
259
+ @test contains (s003, " min 0.010 ns, median 0.020 ns, mean 0.023 ns, 99ᵗʰ 0.040 ns" )
260
+
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
+
266
+ t123 = BenchmarkTools. Trial (BenchmarkTools. Parameters (), [1 ,2 ,3. ], [0 ,0 ,0. ], 0 , 0 )
267
+ s123 = sprint (show, " text/plain" , t123)
268
+ @test contains (s123, " min 1.000 ns, median 2.000 ns, mean 2.000 ns" )
269
+ @test contains (s123, " 0 allocations\n " ) # doesn't print 0 bytes after this
270
+ @test contains (s123, " ◑* " ) # median ◑ is shifted left
271
+ @test contains (s123, " ▁▁█▁▁" ) # has a histogram, mostly zero
272
+ @test contains (s123, " ▁▁▁█ ▁\n " ) # 3.0 fits in last bin, not the overflow
273
+ @test endswith (s123, " 3 ns +" ) # right endpoint rounded to 3, no decimals
274
+ @test contains (s123, " ┌ Trial:" ) # box starting at the type
275
+ @test contains (s123, " 3 samples, each 1 evaluation" ) # caption
276
+
277
+ t456 = BenchmarkTools. Trial (BenchmarkTools. Parameters (), 100 * [1 ,1 ,3 ,14 ,16. ], [0 ,0 ,2 ,0 ,0. ], 456 , 7 )
278
+ s456 = sprint (show, " text/plain" , t456)
279
+ @test contains (s456, " 7 allocations, total 456 bytes" )
280
+ @test contains (s456, " GC time: mean 0.400 ns (0.06%), max 2.000 ns (0.67%)" )
281
+ @test contains (s456, " │ ◔ " ) # 1st quartile lines up with bar
282
+ @test contains (s456, " │ █▁▁▁▁▁▁▁" )
283
+ @test contains (s456, " └ 100 ns " ) # box closing + left endpoint without decimals
284
+
285
+ #=
286
+
287
+ # Some visual histogram checks, in which mean/median should highlight a bar, or not:
288
+
289
+ using BenchmarkTools: Trial, Parameters
290
+ Trial(Parameters(), [pi * 10^9], [0], 0, 0) # one sample
291
+
292
+ # mean == median, one bar. Symbol for median moves to the left.
293
+ Trial(Parameters(), [pi, pi], [0, 0], 0, 0)
294
+ Trial(Parameters(), fill(101, 33), vcat(zeros(32), 50), 0, 0)
295
+
296
+ # mean == median, three bars
297
+ Trial(Parameters(), [3,4,5], [0,0,0], 0, 0)
298
+
299
+ # three bars, including mean not median
300
+ Trial(Parameters(), pi * [1,3,4,4], [0,0,0,100], 1, 1)
301
+
302
+ # three bars, including median & both quartiles, but not mean
303
+ Trial(Parameters(), 99.9 * [1,1,3,14,16], [0,0,99,0,0], 222, 2)
304
+
305
+ # same, but smaller range. Note also max GC is not max time.
306
+ Trial(Parameters(), 999 .+ [1,1,3,14,16], [0,0,123,0,0], 45e6, 7)
307
+
308
+
309
+ # Check that auto-sizing stops on very small widths:
310
+ io = IOContext(stdout, :displaysize => (25,30))
311
+ show(io, MIME("text/plain"), Trial(Parameters(), [3,4,5], [0,0,0], 0, 0))
312
+ show(io, MIME("text/plain"), Trial(Parameters(), repeat(100 * [3,4,5], 10^6), zeros(3*10^6), 0, 0))
313
+
314
+ io = IOContext(stdout, :displaysize => (25,50), :logbins => true) # this is wider
315
+ show(io, MIME("text/plain"), Trial(Parameters(), 100 * [3,4,5], [0,0,0], 0, 0))
242
316
243
- █ █
244
- █▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
245
- 1 ns Histogram: frequency by time 1.01 ns <
317
+ # Check that data off the left is OK, and median still highlighted:
318
+ io = IOContext(stdout, :histmin => 200.123)
319
+ show(io, MIME("text/plain"), Trial(Parameters(), 99.9 * [1,1,3,14,16], [0,0,99,0,0], 222, 2))
246
320
247
- Memory estimate: 0 bytes, allocs estimate: 0. """
321
+ =#
248
322
249
323
end # module
0 commit comments