Skip to content

Commit

Permalink
Add benchmark macro file
Browse files Browse the repository at this point in the history
  • Loading branch information
bennettm committed Mar 13, 2024
1 parent ab5b0b2 commit ca2d518
Showing 1 changed file with 33 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/additional_tools/benchmark_macro.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
@doc draw"""
macro benchmarked(args...)
This macro is needed for getting both benchmark results and a return value from a function.
"""

using BenchmarkTools
using DataFrames


macro benchmarked(args...)
_, params = BenchmarkTools.prunekwargs(args...)
bench, trial, result = gensym(), gensym(), gensym()
trialmin, trialallocs = gensym(), gensym()
tune_phase = BenchmarkTools.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)

display($trial)

$result, $trial
end,
)
end





0 comments on commit ca2d518

Please sign in to comment.