I'm wondering if I found a bug in Julia's BenchmarkTools
or if there's something deeper happening here that I don't understand. Running the following script
function test()
function func1(n)
sum(1:n)
end
function func2(n)
ans = 0
for i = 1:n
ans += i
end
return ans
end
@time func1(100000)
@time func2(100000)
end
works exactly as expected and times both functions. However, using @btime
instead of @time
gives me an undefined error:
ERROR: UndefVarError: func1 not defined
If I move the internal functions outside test()
, both timing versions work fine, but in my actual tests this is not something I can easily do. I prefer using @btime
to @time
, as it's more accurate and robust, but here I clearly can't. Can someone explain if this is a bug or what's going on here?
question from:
https://stackoverflow.com/questions/65836984/julia-btime-cannot-find-internal-function 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…