Reflections on isPalindrome

MachineCode via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue Oct 28 09:07:36 PDT 2014


On Tuesday, 28 October 2014 at 14:09:50 UTC, MattCoder wrote:
> On Tuesday, 28 October 2014 at 13:30:05 UTC, Nordlöw wrote:
>> On Tuesday, 28 October 2014 at 11:51:42 UTC, MattCoder wrote:
>>> I forgot to say that I'm compiling with DMD without any 
>>> compiler hints/optimizations.
>>
>> Try compiling with DMD flag
>>
>> -release
>>
>> and perhaps also
>>
>> -release -noboundscheck
>>
>> to get relevant results.
>>
>> DMD is currently not that good at inlining range primitives.
>
> Interesting!
>
> With -release the second version still faster but only by 10%.
>
> Now with: -release -noboundscheck they are equal and sometimes 
> your version is slightly faster by ~3 milliseconds.
>
> Matheus.

I'm very surprise. If they either equal or fast sometimes the 
compiler did great optizations or it's just a multicore processor 
that's helping or what else? the first version (from your post, 
the one using ranges) change in each iteration two pointers (in 
pop*() calls) and request r's length 3 times (in .empty calls) 
while the second doesn't, just run until an already know index 
(when enter in the loop) and access two index in each iteration. 
This without consider the amount of ifs.

I don't know, maybe I just thinking in the C-way as that code 
would run.


More information about the Digitalmars-d-learn mailing list