Improve std::sort over std::array<T, N> for small values of N
Morwenn Ed
morwenn29@hotmail.fr
Sun Aug 2 19:16:00 GMT 2015
I have developed a small library to complete std::sort. Basically, the
idea is to use specific decicated algorithms for a small number of
values when that number of values is known at compile time. You can
find the library here: https://github.com/Morwenn/cpp-sort
When given an std::array, the sort function of the library uses a specific
sorting algorithm (based on sorting networks) for the given number of
values if it has one and falls back to std::sort if it doesn't. I
believe that it could be possible to add an overload to the
implementation of std::sort which would take instances of
std::array<T, N>::iterator and use a specific sorting algorithm
for small values of N. It would incur no runtime overhead and would
allow to sort small arrays for "free" instead of using the general
purpose version of std::sort which sometimes feel overkill for the job.
Would you be interested in such an optimization for libstdc++?
More information about the Libstdc++
mailing list