Skip to content

Sorting wrt multiple arrays #12

Closed
Closed
@matthieugomez

Description

@matthieugomez

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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions