Apparent mismatch of run times during summation

It’s not that @btime does this, it’s constant propagation in the compiler. When you have simple functions, you can prevent the compiler from constant propegating into the benchmark by timing like so

julia> @btime f1($Ref(1)[])
  29.406 ns (1 allocation: 16 bytes)
0.5

julia> @btime f2($Ref(1)[])
  37.100 ns (1 allocation: 32 bytes)
0.5 - 0.5im
2 Likes