Function control flow

julia> @btime wage1($pp)
  0.017 ns (0 allocations: 0 bytes)
1.912

julia> @btime wage2($pr)
  0.017 ns (0 allocations: 0 bytes)
1.912

julia> @btime wage3(.956)
  0.017 ns (0 allocations: 0 bytes)
1.912

That the compiler defeated the benchmark.

1 Like

Sorry, I’m a noob here. What does ‘compiler defeated the benchmark’ mean? What is the purpose of using ‘$’? Thanks

I recommend reading the QuickStart of BenchmarkTools.jl. It answers both questions.

If you use the Ref trick to get around it, wage3 slows down as much as the others:

julia> @btime wage1($(Ref(pp))[])
  1.267 ns (0 allocations: 0 bytes)
1.912

julia> @btime wage2($(Ref(pr))[])
  1.269 ns (0 allocations: 0 bytes)
1.912

julia> @btime wage3($(Ref(.956))[])
  1.268 ns (0 allocations: 0 bytes)
1.912
2 Likes