Skip to content

On the sorting algorithm #20

@putianyi889

Description

@putianyi889

Benchmarking 5 different methods:

using TupleTools, Plots, StaticArrays, SortingNetworks
times1 = zeros(25)
times2 = zeros(25)
times3 = zeros(25)
times4 = zeros(25)
times5 = zeros(25)
for N in 1:25
    print(N)
    t = tuple(rand(N)...)
    times1[N] = @belapsed TupleTools.sort(t)
    times2[N] = @belapsed Tuple(sort!(collect(t)))
    times3[N] = @belapsed sort!(MVector(t)).data
    times4[N] = @belapsed sort(SVector(t)).data
    times5[N] = @belapsed swapsort(t)
end
plot([times1 times2 times3 times4 times5], yaxis=:log)

image

TupleTools.sort only has advantage at very small tuples (<=6) so my proposal is to change the method name to tuplesort and only apply it for small tuples. For such a small size it could be possible to generate fully performant codes rather than the merging algorithm.

Edit: added SortingNetworks.swapsort which is even faster than TupleTools.sort

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions