Code speed and C++

Joseph Wakeling joseph.wakeling at webdrake.net
Sat Apr 17 03:34:39 PDT 2010


bearophile wrote:
>> This is the middle parts (the two loops) of Yzlm.objectReputationUpdate compiled with ldc, this is one of the two main hot spots of the program, the you can compared this asm with the asm of the same part from the C++ version:
> 
> To find why the C++ code is faster you can show me the equivalent C++ code that I can compile myself, or you can compile your C++ code and show me the asm of the two functions that are hot spots.

I took a little time last night and wrote up a C++ version that is much
closer in design to the D code (as well as smaller, simpler, less hell
to read...).  It has libboost as a dependency for random number
generation and for the BOOST_FOREACH macro.

Following your observation with D, it looks like the C++ also benefits
from using references in the FOREACH loops for elements larger than
size_t -- this shaves about 20s off running time on my machine.  Either
way, like its uglier predecessor it's quite a bit faster than DMD or
LDC.  Unfortunately I can't get llvm-g++ running on my machine, or I
would compare performance there too.

Hope this makes an interesting point of comparison. :-)

Best wishes,

    -- Joe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: fric.cpp
Type: text/x-c++src
Size: 6139 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100417/2e0399ed/attachment.cpp>


More information about the Digitalmars-d-learn mailing list