`@btime 5+2`

@btime 5+2 reports a 100x speed up in Julia 1.0 vs. Julia 0.6.4. This is too good to be true. Perhaps constant propagation is affecting the result.

Am I misusing @btime here? What would be the correct way to measure the time for integer addition?

julia> @btime x + y setup = (x = rand(Int); y = rand(Int));
  1.448 ns (0 allocations: 0 bytes)

@btime 5 + 2 just gets constant-folded.

3 Likes

Note that for something as cheap as this, there’s basically no way to benchmark it correctly. There are properties of the instructions that could be measured (not with BenchmarkTools) but none of those properties will give you the correct time a program will take to run if you just add them together.

The number you get from the “correct” @btime is all overhead. Assuming this is not an ancient processor, the add should be at least 5-20x faster than that.

7 Likes