std.algorithm.sort slower than C++'s std::sort for integer arrays

Atila Neves atila.neves at gmail.com
Fri Nov 9 09:34:10 UTC 2018


On Thursday, 8 November 2018 at 17:43:47 UTC, JN wrote:
> On Thursday, 8 November 2018 at 15:28:25 UTC, Andrea Fontana 
> wrote:
>> I've already said in the past that we probably can improve 
>> sort() function tuning it for some cases (f.e. short int or 
>> bytes...). Many languages use some hybrid algorithms like 
>> timsort & similar. I don't know what D do on phobos...
>>
>> Did you consider this?
>>
>> Andrea
>
> https://dlang.org/phobos/std_algorithm_sorting.html#sort
>
> "Algorithms
> Introsort is used for unstable sorting and Timsort is used for 
> stable sorting."

That is indeed what the ddoc says. The code, however:

----------------------
         static if (ss == SwapStrategy.unstable)
             quickSortImpl!(lessFun)(r, r.length);
         else //use Tim Sort for semistable & stable
             TimSortImpl!(lessFun, Range).sort(r, null);
----------------------



More information about the Digitalmars-d mailing list