Optimizing Java using D

Joseph Rushton Wakeling via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 21 01:55:15 PDT 2014


On 21/06/14 03:48, Peter Alexander via Digitalmars-d wrote:
> On Saturday, 21 June 2014 at 01:07:20 UTC, safety0ff wrote:
>> std.algorithm.sort with SwapStrategy.unstable is considerably slower than his,
>> whereas builtin sort is  abysmal.
>>
>> I find that generally using SwapStrategy.stable performs better.
>> This isn't universal though as there are cases where it is slower.
>
> wat
>
> Shouldn't unstable be faster, otherwise we might as well just alias unstable =
> stable!?

I can't find the issue in bugzilla, but IIRC there was a problem with unstable 
sort where it would produce worst-case-scenario behaviour in the event of being 
given input that had only a few unsorted elements.

I ran into it when implementing some of the algorithms in Dgraph: appending one 
new element to an array and using sort() would generate quadratic behaviour.

That case of "mostly sorted" input seems to also be present in the problem 
described here.


More information about the Digitalmars-d mailing list