@btime with local function --> not defined


dear J wizards—how do I use @btime inside a function with a passed argument?

julia> function testme( afun ); @btime begin afun(2) end end
testme (generic function with 1 method)

julia> testme( println )
ERROR: UndefVarError: afun not defined

@atime works, but afaik, it is not recommended for benchmarking.


With interpolation, just like any other argument:

function testme(afun)
    @btime $afun(2) 
julia> f = x -> 2x
(::#36) (generic function with 1 method)

julia> testme(f)
  1.645 ns (0 allocations: 0 bytes)