Skip to content

Sorting could be much faster #1254

Open
@jw3126

Description

@jw3126
using SortingNetworks: swapsort
using StaticArrays

for N in 5:10
    @show N
    @btime sort($v) setup=(v = SVector{$N}(rand($N)))
    println("swapsort")
    @btime swapsort($v) setup=(v = SVector{$N}(rand($N)))
end
N = 5
sort
  7.938 ns (0 allocations: 0 bytes)
swapsort
  2.000 ns (0 allocations: 0 bytes)
N = 6
sort
  12.933 ns (0 allocations: 0 bytes)
swapsort
  2.190 ns (0 allocations: 0 bytes)
N = 7
sort
  20.211 ns (0 allocations: 0 bytes)
swapsort
  2.920 ns (0 allocations: 0 bytes)
N = 8
sort
  23.454 ns (0 allocations: 0 bytes)
swapsort
  3.460 ns (0 allocations: 0 bytes)
N = 9
sort
  28.281 ns (0 allocations: 0 bytes)
swapsort
  4.570 ns (0 allocations: 0 bytes)
N = 10
sort
  33.484 ns (0 allocations: 0 bytes)
swapsort
  5.280 ns (0 allocations: 0 bytes)

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