It seems like DMD doesn't optimize tail recursion very well
pragma
pragma_member at pathlink.com
Fri Jun 9 08:55:29 PDT 2006
In article <e6c2kn$m48$1 at digitaldaemon.com>, James Pelcis says...
>My results (averaged and rounded) were 5,575,010,530 for C++ and
>8,339,840,041 for D. Since it was with the same linker, optimizer,
>etc., this is a bad sign. Is the problem in the code or the compiler?
I can confirm. Using your source code, comparing DMC to DMD, I got:
C:\home\pragma\src\test>ackcpp.exe
7982698959 clock cycles elapsed.
C:\home\pragma\src\test>ackd.exe
10881160506 clock cycles elapsed.
Now on a whim, I added "extern(C)" to the definition of Ack() like so:
> extern(C) int Ack(int a, int b){ /* ... */ }
And got this:
C:\home\pragma\src\test>ackcpp.exe
7371540535 clock cycles elapsed.
C:\home\pragma\src\test>ackd.exe
7057883217 clock cycles elapsed.
With that change D is still lagging, but by *significantly* less - so there's
another factor here. So there is some kind of drawback to using the D callspec
with recursion. My guess is that exploring the ASM using obj2asm would help
show why.
- EricAnderton at yahoo
More information about the Digitalmars-d
mailing list