What would be the fastest way to get the parity of sorting permutations for vectors with very small size?
The obvious way is to use the
sortperm! function and the parity function from
sortperm! costs 85ns on my laptop:
julia> p = zeros(Int64, 8); julia> v = rand(Int8, 8); julia> @btime sortperm!($p, $v); 85.254 ns (1 allocation: 16 bytes) julia> using Combinatorics julia> parity(p) 1
I need to calculate the parity for billions of times. Given that the vectors have very small size: (<15), is there any optimization I can do to improve the performance?