Closed
Description
What's the best way to sort lexicographically wrt 2 arrays a and b ?
The code below is quite slow, so I'm wondering whether there is a better solution
n = 1_000_000
a = rand(1:n, n)
b = rand(1:10, n)
@time sortperm([(a[i], b[i]) for i in 1:length(a)])
#elapsed time: 9.676994989 seconds (287943584 bytes allocated, 16.39% gc time)
@time sortperm([(sub(a,i)[1], sub(b,i)[1]) for i in 1:length(a)], order= Base.Order.Lexicographic)
#elapsed time: 9.446759537 seconds (560247620 bytes allocated, 17.83% gc time)
Metadata
Metadata
Assignees
Labels
No labels