This works:
using BenchmarkTools
fun = () -> sqrt(3)
@benchmark fun()
This however:
benchit(f) = @benchmark f()
benchit(fun)
Results in:
ERROR: UndefVarError: f not defined
Other macros work, e.g.:
timeit(f) = @time f()
timeit(fun)
Am I missing something, or is this a problem with the @benchmark
macro? Perhaps it’s not escaping the expression correctly? If I create the following two macros:
macro m1(ex) :($(esc(ex))) end
macro m2(ex) :($ex) end
The first one works when called through a function like above, while the second one gives the same ERROR: UndefVarError: f not defined
.