I have a function. I want to benchmark it for various inputs (originally I am solving a differential equations over various timespans). Naturally I would do something like:
using BenchmarkTools
bs =
for l in [10,100,1000]
b = @benchmark rand(l).^2
end
(probably compressed using map()
, but this makes the mwe clearer)
This, however, yields an error:
UndefVarError: l not defined
Stacktrace:
[1] var"##core#519"()
@ Main ~/.julia/packages/BenchmarkTools/7xSXH/src/execution.jl:489
[2] var"##sample#520"(::Tuple{}, __params::BenchmarkTools.Parameters)
@ Main ~/.julia/packages/BenchmarkTools/7xSXH/src/execution.jl:495
[3] _run(b::BenchmarkTools.Benchmark, p::BenchmarkTools.Parameters; verbose::Bool, pad::String, kwargs::Base.Pairs{Symbol, Integer, NTuple{4, Symbol}, NamedTuple{(:samples, :evals, :gctrial, :gcsample), Tuple{Int64, Int64, Bool, Bool}}})
@ BenchmarkTools ~/.julia/packages/BenchmarkTools/7xSXH/src/execution.jl:99
[4] #invokelatest#2
@ ./essentials.jl:718 [inlined]
[5] #run_result#45
@ ~/.julia/packages/BenchmarkTools/7xSXH/src/execution.jl:34 [inlined]
[6] run(b::BenchmarkTools.Benchmark, p::BenchmarkTools.Parameters; progressid::Nothing, nleaves::Float64, ndone::Float64, kwargs::Base.Pairs{Symbol, Integer, NTuple{5, Symbol}, NamedTuple{(:verbose, :samples, :evals, :gctrial, :gcsample), Tuple{Bool, Int64, Int64, Bool, Bool}}})
@ BenchmarkTools ~/.julia/packages/BenchmarkTools/7xSXH/src/execution.jl:117
[7] #warmup#54
@ ~/.julia/packages/BenchmarkTools/7xSXH/src/execution.jl:169 [inlined]
[8] warmup(item::BenchmarkTools.Benchmark)
@ BenchmarkTools ~/.julia/packages/BenchmarkTools/7xSXH/src/execution.jl:169
[9] macro expansion
@ ~/.julia/packages/BenchmarkTools/7xSXH/src/execution.jl:393 [inlined]
[10] top-level scope
@ In[42]:4
[11] eval
@ ./boot.jl:373 [inlined]
[12] include_string(mapexpr::typeof(REPL.softscope), mod::Module, code::String, filename::String)
@ Base ./loading.jl:1196
Is there a way to get around this, or otherwise accomplish what I want to accomplish?