BenchmarkTools.jl
BenchmarkTools.jl copied to clipboard
@btime not printing as expected in a loop
When I'm comparing different versions of a function I like to do something like
function func1(x)
# code
end
function func2(x)
# code
end
function func3(x)
# code
end
for i in 1:3
print(i, ": ")
@btime $(Symbol(:func, i))($(12345))
end
I'd expect this to print something like
1: 19.682 μs (914 allocations: 42.84 KiB)
2: 21.141 μs (914 allocations: 42.84 KiB)
3: 21.889 μs (914 allocations: 42.84 KiB)
but I get
19.682 μs (914 allocations: 42.84 KiB)
2: 21.141 μs (914 allocations: 42.84 KiB)
3: 21.889 μs (914 allocations: 42.84 KiB)
What's going on?
I'm having the same issue and it would be great to get some insight on this.
Works fine for me:
julia> for i in 1:3
print(i, ": ")
@btime $(Symbol(:func, i))($(Ref(12345))[])
end
1: 1.214 ns (0 allocations: 0 bytes)
2: 1.017 ns (0 allocations: 0 bytes)
3: 1.058 ns (0 allocations: 0 bytes)
This looks like a common bug when running in Atom. Often when I print to the terminal, the first print is ignored. I therefore add a print("") if I am trying to align something.