diff --git a/src/execution.jl b/src/execution.jl index a031e652..6e29225a 100644 --- a/src/execution.jl +++ b/src/execution.jl @@ -639,12 +639,14 @@ returning the value of the expression. Unlike `@time`, it uses the `@benchmark` macro, and accepts all of the same additional parameters as `@benchmark`. The printed time -is the *minimum* elapsed time measured during the benchmark. +is the *minimum* elapsed time measured during +the benchmark, unless there are allocations then +*mean* as the main valuable timing. """ macro btime(args...) _, params = prunekwargs(args...) bench, trial, result = gensym(), gensym(), gensym() - trialmin, trialallocs = gensym(), gensym() + trialmin, trialmean, trialallocs = gensym(), gensym(), gensym() tune_phase = hasevals(params) ? :() : :($BenchmarkTools.tune!($bench)) return esc( quote @@ -653,18 +655,29 @@ macro btime(args...) $tune_phase local $trial, $result = $BenchmarkTools.run_result($bench) local $trialmin = $BenchmarkTools.minimum($trial) + local $trialmean = $BenchmarkTools.mean($trial) local $trialallocs = $BenchmarkTools.allocs($trialmin) - println( - " ", - $BenchmarkTools.prettytime($BenchmarkTools.time($trialmin)), - " (", - $trialallocs, - " allocation", - $trialallocs == 1 ? "" : "s", - ": ", - $BenchmarkTools.prettymemory($BenchmarkTools.memory($trialmin)), - ")", - ) + if $trialallocs == 0 + println( + " ", + $BenchmarkTools.prettytime($BenchmarkTools.time($trialmin)), + " (minimum time; 0 allocations)", + ) + else + println( + " ", + $BenchmarkTools.prettytime($BenchmarkTools.time($trialmean)), + " (mean time; miniumum is ", + $BenchmarkTools.prettytime($BenchmarkTools.time($trialmin)), + ", ", + $trialallocs, + " allocation", + $trialallocs == 1 ? "" : "s", + ": ", + $BenchmarkTools.prettymemory($BenchmarkTools.memory($trialmin)), + ")", + ) + end $result end, ) diff --git a/test/ExecutionTests.jl b/test/ExecutionTests.jl index 235794ff..b296a64c 100644 --- a/test/ExecutionTests.jl +++ b/test/ExecutionTests.jl @@ -333,7 +333,7 @@ let fname = tempname() end s = read(fname, String) try - @test occursin(r"[0-9.]+ \w*s \([0-9]* allocations?: [0-9]+ bytes\)", s) + @test occursin(r"[0-9.]+ \w*s \(minimum time; [0-9]* allocations\)", s) catch println(stderr, "@btime output didn't match ", repr(s)) rethrow()