Faster sort?

John Colvin via Digitalmars-d digitalmars-d at puremagic.com
Thu Apr 7 02:23:16 PDT 2016


On Thursday, 7 April 2016 at 09:01:14 UTC, tsbockman wrote:
> On Thursday, 7 April 2016 at 08:23:09 UTC, John Colvin wrote:
>> But it definitely can eliminate an unused result. My 
>> prediction: you took an array and sorted it, then did nothing 
>> with the result, so it rightly concluded that there was no 
>> point doing the sort. In any given case the compiler could be 
>> removing some or all of the work.
>>
>> Laborious approach that defeats the optimisations you don't 
>> want while keeping the ones you do:
>
> It's easier to just output the result in some form. I typically 
> calculate and display a checksum of some sort.

Take care with this approach. For example, calling a pure 
function (whether D pure or some optimiser inferred sort of 
purity) repeatedly in a loop can sometimes cause the loop to be 
reduced to a single iteration (doesn't apply in this case, 
because of randomly generating data each iteration).


More information about the Digitalmars-d mailing list