Performance measurement of floating number division vs multiplication

Benchmarking at the ns scale is very tricky. The following benchmark shows muhc more of what you would expect

x=rand(100)
julia> @benchmark foldl(*, $x)
BenchmarkTools.Trial: 10000 samples with 986 evaluations.
 Range (min … max):  49.161 ns … 112.373 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     49.452 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   51.039 ns ±   3.411 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  ██        ▂▅      ▄▄         ▁▃                              ▁
  ██▃▄▅▆▆▇▇▆███▇▆█▇▇███▇██▇▇▇▇▅██▇▆▆▅▅▅▆▆▅▅▆▅▅▅▅▅▄▄▄▄▅▄▄▄▅▄▄▃▅ █
  49.2 ns       Histogram: log(frequency) by time      64.5 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.

julia> @benchmark foldl(/, $x)
BenchmarkTools.Trial: 10000 samples with 792 evaluations.
 Range (min … max):  154.717 ns … 295.852 ns  ┊ GC (min … max): 0.00% … 0.00%
 Time  (median):     157.114 ns               ┊ GC (median):    0.00%
 Time  (mean ± σ):   160.321 ns ±   8.681 ns  ┊ GC (mean ± σ):  0.00% ± 0.00%

  █▄▄▄▄▅▆     ▁     ▁      ▁▅▁▁▂▂▂▃                             ▁
  ████████▇██████▇█████████████████▇█▇▇▆▇▇▇▇▆▆▅▆▇▅▅▅▅▅▄▄▅▆▅▅▄▃▅ █
  155 ns        Histogram: log(frequency) by time        189 ns <

 Memory estimate: 0 bytes, allocs estimate: 0.
2 Likes