Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fuse broadcasted float and complex operations
`float.(complex(v))` is less performant than `float.(complex.(v))`. Relevant docs: https://docs.julialang.org/en/v1/manual/performance-tips/#More-dots:-Fuse-vectorized-operations Relevant microbenchmarks (nightly Julia): ``` julia> f(v) = float.(complex(v)) f (generic function with 1 method) julia> g(v) = float.(complex.(v)) g (generic function with 1 method) julia> h(v) = map(float ∘ complex, v) h (generic function with 1 method) julia> setprecision(2^11) 2048 julia> using BenchmarkTools julia> f(BigFloat[1, 2, 3]) 3-element Vector{Complex{BigFloat}}: 1.0 + 0.0im 2.0 + 0.0im 3.0 + 0.0im julia> g(BigFloat[1, 2, 3]) 3-element Vector{Complex{BigFloat}}: 1.0 + 0.0im 2.0 + 0.0im 3.0 + 0.0im julia> h(BigFloat[1, 2, 3]) 3-element Vector{Complex{BigFloat}}: 1.0 + 0.0im 2.0 + 0.0im 3.0 + 0.0im julia> @benchmark f(v) setup=(v = rand(BigFloat, 2^16);) BenchmarkTools.Trial: 223 samples with 1 evaluation. Range (min … max): 4.225 ms … 39.270 ms ┊ GC (min … max): 0.00% … 74.99% Time (median): 4.474 ms ┊ GC (median): 0.00% Time (mean ± σ): 7.535 ms ± 5.772 ms ┊ GC (mean ± σ): 30.20% ± 27.14% █▂ ▃ ▃ ██▅▄▁▁▁▁▁▁▁▁▁▁▁▁▁▆█▄▁▁▁▁▁▁▁▁▁▁▁▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█▆▁▁▁▁▄ ▅ 4.23 ms Histogram: log(frequency) by time 21.3 ms < Memory estimate: 23.00 MiB, allocs estimate: 131080. julia> @benchmark g(v) setup=(v = rand(BigFloat, 2^16);) BenchmarkTools.Trial: 223 samples with 1 evaluation. Range (min … max): 3.882 ms … 15.182 ms ┊ GC (min … max): 0.00% … 72.54% Time (median): 4.101 ms ┊ GC (median): 0.00% Time (mean ± σ): 7.448 ms ± 4.387 ms ┊ GC (mean ± σ): 44.37% ± 32.61% █▅ ██▄▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▅▁▁▁▁▁▁▁▁▄▁▁▅▆▇▆▇▇▆▆▆▅▇▆▇▆▅▇▇▇▅▇▇▇█ ▅ 3.88 ms Histogram: log(frequency) by time 14.9 ms < Memory estimate: 22.00 MiB, allocs estimate: 131074. julia> @benchmark h(v) setup=(v = rand(BigFloat, 2^16);) BenchmarkTools.Trial: 213 samples with 1 evaluation. Range (min … max): 3.832 ms … 20.391 ms ┊ GC (min … max): 0.00% … 79.66% Time (median): 4.118 ms ┊ GC (median): 0.00% Time (mean ± σ): 8.597 ms ± 5.860 ms ┊ GC (mean ± σ): 51.76% ± 35.27% █▄ ██▅▄▁▁▁▁▁▁▁▁▁▁▁▁▄▄▁▁▁▁▁▄▇▆▆▅▅▅▆▅▅▅▄▄▅▆▆▄▆▅▅▅▄▇▆▅▅▆▅▆▅▅▆▆▅▇ ▅ 3.83 ms Histogram: log(frequency) by time 19.9 ms < Memory estimate: 22.00 MiB, allocs estimate: 131074. ```
- Loading branch information