I wonder what the fastest way is to apply a permutation to an array. Three approaches that I checked are:
julia> A = rand(10000); julia> permutation = sortperm(A); julia> @btime $A[$permutation]; 11.700 μs (3 allocations: 78.22 KiB) julia> @btime $A .= $A[$permutation]; 13.200 μs (3 allocations: 78.22 KiB) julia> @btime permute!($A,$permutation); 42.000 μs (2 allocations: 78.20 KiB)
None of these methods seem to be inplace (for the first one it is not surprising), I did however not expect the first approach to be the fastest. Any ideas what is causing this?