Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default to mean time, when for allocations #340

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions src/execution.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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,
)
Expand Down
2 changes: 1 addition & 1 deletion test/ExecutionTests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down