# Which sorting algorithm should I use?

**URL:** <https://discourse.julialang.org/t/which-sorting-algorithm-should-i-use/16999>\
**Category:** Performance\
**Tags:** sort, sortperm\
**Created:** [October 31, 2018, 9:56am UTC](https://discourse.julialang.org/t/which-sorting-algorithm-should-i-use/16999 "2018-10-31T09:56:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sam/32/4101_2.png) [@Sam](https://discourse.julialang.org/u/Sam)\
**Post date:** [October 31, 2018, 9:56am UTC](https://discourse.julialang.org/t/which-sorting-algorithm-should-i-use/16999/1 "2018-10-31T09:56:57Z")

</div>

I am currently writing an algorithm where I have to use `sortperm` multiple times. After reading about this issue [https://github.com/JuliaLang/julia/issues/939#issuecomment-288758163](https://github.com/JuliaLang/julia/issues/939#issuecomment-288758163) I realized that there seem to be some problems with the performance of `sortperm`, and I can therefore perhaps improve the performance of my code by using a suitable sorting algorithm.

In the algorithm that I am writing, I have to sort a quite small vector (length \< 10000) where the elements in the vector are Floats that are of the same magnitude and close to each other. I am currently using the default setting in `sortperm`. But for this particular case, there might be some other sorting algorithm that is preferable?

---

<div class="post-metadata">

**Author:** ![Liso](https://avatars.discourse-cdn.com/v4/letter/l/898d66/32.png) [@Liso](https://discourse.julialang.org/u/Liso)\
**Post date:** [October 31, 2018, 10:54am UTC](https://discourse.julialang.org/t/which-sorting-algorithm-should-i-use/16999/2 "2018-10-31T10:54:00Z")

</div>

You could see that between [this comment](https://github.com/JuliaLang/julia/issues/939#issuecomment-288758163) and [this comment](https://github.com/JuliaLang/julia/issues/939#issuecomment-413280132) `sortperm!` improved from `14.113 μs (3 allocations: 48 bytes)` to `212.952 ns (3 allocations: 48 bytes)` so what is best could be changed with Julia’s implementations.

Maybe writing some benchmark test function which return best function/algorithm for representative sample of your data would be best solution?

---

<div class="post-metadata">

**Author:** ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)\
**Post date:** [October 31, 2018, 12:19pm UTC](https://discourse.julialang.org/t/which-sorting-algorithm-should-i-use/16999/3 "2018-10-31T12:19:09Z")

</div>

Use radix sort from SortingAlgorithms
