is D so slow?
jlquinn at optonline.net
Sun Jun 15 19:05:58 PDT 2008
Unknown W. Brackets Wrote:
> What about switches? Your program uses arrays; if you have array bounds
> checks enabled, that could easily account for the difference.
> One way to see is dump the assembly (I think there's a utility called
> dumpobj included with dmd) and compare. Obviously, it's doing something
> differently - there's nothing instrinsically "slower" about the language
> for sure.
> Also - keep in mind that gdc doesn't take advantage of all the
> optimizations that gcc is able to provide, at least at this time. A
> couple of bytes can go a long long way if not optimized right.
There's another classic benchmark issue that you could be stumbling over. The sample code you posted throws away the results inside the function.
GCC C can detect that the result of the computations are not used, and optimize everything out of existence. That kind of difference could easily explain the speed difference you're seeing.
If you're going to do this kind of micro-benchmark, you need to print the result of computation or otherwise convince the compiler you need the result.
More information about the Digitalmars-d-learn