I was quite surprised to see this performance difference:
julia> using BenchmarkTools
julia> N = 1000;
julia> @btime complex.(rand($N, $N), rand($N, $N));
4.852 ms (6 allocations: 30.52 MiB)
julia> @btime rand(ComplexF64, $N, $N);
11.201 ms (2 allocations: 15.26 MiB)
It’s even worse for smaller N
:
julia> N = 100;
julia> @btime complex.(rand($N, $N), rand($N, $N));
20.001 μs (6 allocations: 312.73 KiB)
julia> @btime rand(ComplexF64, $N, $N);
99.300 μs (2 allocations: 156.33 KiB)
Is this a known performance issue? I would have expected rand(ComplexF64, ...)
to be the fastest of the two.
I’m on v1.5.3.