Slower than Python

Steven Schveighoffer schveiguy at yahoo.com
Mon Mar 4 07:43:31 PST 2013


On Sun, 03 Mar 2013 22:58:07 -0500, deadalnix <deadalnix at gmail.com> wrote:

> On Monday, 4 March 2013 at 03:20:57 UTC, jerro wrote:
>>> Maybe it is time to look at the python implementation and see why it  
>>> is faster.
>>
>> It isn't faster:
>>
>> $ time python3 test.py
>>
>> real    0m14.217s
>> user    0m14.209s
>> sys     0m0.004s
>> $ gdmd -O -inline -release -noboundscheck test
>> $ time ./test
>>
>> real    0m5.323s
>> user    0m5.312s
>> sys     0m0.008s
>>
>> D code here uses the same string as the python code, not the one in  
>> cvk012c's D code.
>
> Using noboundcheck isn't fair as you give up on safety, so you are not  
> equivalent to python either.

In this type of test, there is no danger with using noboundscheck.  It's a  
very fair switch to use, D is just able to do it where python is not.  A  
sufficiently smart compiler could eliminate the bounds check for this  
code, since it can be proven not to go out of bounds (in fact, a simple  
run without the noboundscheck proves it in very deterministic code like  
this).

-Steve


More information about the Digitalmars-d mailing list