This is asked every other week, so probably we should have it directly in BenchmarkTools
:
julia> @eval BenchmarkTools macro btimed(args...)
_, params = prunekwargs(args...)
bench, trial, result = gensym(), gensym(), gensym()
trialmin, trialallocs = gensym(), gensym()
tune_phase = hasevals(params) ? :() : :($BenchmarkTools.tune!($bench))
return esc(quote
local $bench = $BenchmarkTools.@benchmarkable $(args...)
$BenchmarkTools.warmup($bench)
$tune_phase
local $trial, $result = $BenchmarkTools.run_result($bench)
local $trialmin = $BenchmarkTools.minimum($trial)
$result, $BenchmarkTools.time($trialmin)
end)
end
@btimed (macro with 1 method)
julia> BenchmarkTools.@btimed sin(12.3)
(-0.26323179136580094, 1.41)
(the time is returned in nanoseconds)