Finding large difference b/w execution time of c++ and D codes for same problem

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Wed Feb 13 09:10:47 PST 2013


On 02/13/2013 04:41 PM, Joseph Rushton Wakeling wrote:
> On 02/13/2013 04:17 PM, FG wrote:
>> Good point about choosing the right type of floating point numbers.
>> Conclusion: when there's enough space, always pick double over float.
>> Tested with GDC in win64. floats: 16.0s / doubles: 14.1s / reals: 11.2s.
>> I thought to myself: cool, I almost beat the 13.4s I got with C++, until I
>> changed the C++ code to also use doubles and... got a massive speedup: 7.1s!
>
> Yea, ditto for C++: 5.3 sec with double, 9.3 with float (using g++ -O3).

Just to update on times.  I was running another large job at the same time as 
doing all these tests, so there was some slowdown.  Current results are:

-- with g++ -O3 and using double rather than float: about 4.3 s

-- with clang++ -O3 and using double rather than float: about 3.1 s

-- with gdmd -O -release -inline:

     D code serial with dimension 32768 ...
       using floats Total time: 17.179 [sec], Julia value: 0
       using doubles Total time: 10.298 [sec], Julia value: 0
       using reals Total time: 17.126 [sec], Julia value: 0

-- with ldmd2 -O -release -inline:

     D code serial with dimension 32768 ...
       using floats Total time: 3.548 [sec], Julia value: 0
       using doubles Total time: 2.708 [sec], Julia value: 0
       using reals Total time: 4.371 [sec], Julia value: 0

-- with dmd -O -release -inline:

     D code serial with dimension 32768 ...
       using floats Total time: 15.696 [sec], Julia value: 0
       using doubles Total time: 7.233 [sec], Julia value: 0
       using reals Total time: 28.71 [sec], Julia value: 0

You'll note that I added a writeout of the global juliaValue in order to check 
that certain calculations weren't being optimized away.

It's striking that in this case GDC is slower not only than LDC but also DMD. 
Current GDC is based off 2.060 as far as I know, whereas current LDC has 
upgraded to 2.061, so are there some changes between D 2.060 and 2.061 that 
could explain this?

It's also interesting that clang++ produces a faster executable than g++, but 
it's not possible to make a direct LLVM vs GCC comparison here, as g++ is GCC 
4.7.2 whereas GDC is based off a GCC snapshot.

My guess would be that it's some combination of LLVM superiority in a particular 
case here, together with some 2.060 --> 2.061.

Are these results comparable to what other people are getting?

I can confirm that where code of mine is concerned, GDC still seems to have the 
edge in terms of executable speed ...


More information about the Digitalmars-d-learn mailing list