JuliaCI / BenchmarkTools.jl

A benchmarking framework for the Julia language
Other
617 stars 100 forks source link

Function undefined for @btime when using for loop #280

Open bojeryd91 opened 2 years ago

bojeryd91 commented 2 years ago

Unlike @time, @btime throws an error that fun is undefined when I run

using BenchmarkTools
f(x) = x^2; g(x) = x^3; h(x) = x^4
@btime f(2.0) # This works

for fun in (f, g, h)
    @time  fun(1.0)
    @btime fun(1.0) # This throws UndefVarError: fun not defined
end

I am running BenchmarkTools v1.3.1 and Julia 1.6.0

vchuravy commented 2 years ago

Please quote your code snippets to not ping other people.

gdalle commented 1 year ago

Note that it works if you interpolate $fun, which is the right thing to do anyway. But it still shouldn't error without interpolation