Code speed [was: Re: Memory leak with dynamic array]

Joseph Wakeling joseph.wakeling at webdrake.net
Tue Apr 13 16:15:15 PDT 2010


Don wrote:
> The D code compiles directly to a memset and memcpy, which are
> intrinsics. There's no way C++ could beat it.

OK.  I'm just bemused about why -- having solved the memory leak -- my D
code is running significantly slower than equivalent C++ code.

For now I'm just playing with D by doing a rewrite of some C++ code I
did for a project a while back -- to see if I can write a neater version
of the code in the new language, and learn something about D in the
process.  I may have fallen into the trap you described earlier, of just
'translating' C++ style code directly into D, but I don't think that's
the issue here.

There are a couple of algorithmic inefficiencies in there with
deliberate reason, but removing them for testing purposes doesn't
improve matters.  The array append is slow, but it's not the major part
of the running time of the program.

For the sake of clarity, I've attached the complete code.  The really
important part to look at is the file yzlm.d in the opCall() function
and class functions objectReputationUpdate() and userReputationUpdate().
This is a reputation-generating process which takes a set of ratings by
users of objects, and uses them to iteratively recalculate user
reputation and re-aggregate the ratings taking this into account.

I don't see anything particularly bad about the way these algorithms are
written but maybe they are imperfectly D-ish ... :-)

Best wishes,

    -- Joe
-------------- next part --------------
A non-text attachment was scrubbed...
Name: yzlm.d
Type: text/x-dsrc
Size: 3132 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100414/39e22f92/attachment.d>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: avg.d
Type: text/x-dsrc
Size: 1165 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100414/39e22f92/attachment-0001.d>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: core.d
Type: text/x-dsrc
Size: 224 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100414/39e22f92/attachment-0002.d>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: test.d
Type: text/x-dsrc
Size: 1479 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20100414/39e22f92/attachment-0003.d>


More information about the Digitalmars-d-learn mailing list