D speed compared to C++

Sean Kelly sean at invisibleduck.org
Tue Mar 18 14:08:24 PDT 2008


== Quote from Matthew Allen (matt.allen at removeme.creativelifestyles.com)'s article
> I am looking to use D for programming a high speed vision application which was previously written
in C/C++. I have done some arbitary speed tests and am finding that C/C++ seems to be faster than D
by a magnitude of about 3 times. I have done some simple loop tests that increment a float value by
some number and also some memory allocation/deallocation loops and C/C++ seems to come out on
top each time. Is D meant to be faster or as fast as C/C++ and if so how can I optimize the code. I am
using -inline, -O, and -release.
> An example of a simple loop test I ran is as follows:
> DWORD start = timeGetTime();
> 	int i,j,k;
> 	float dx=0;
>     for(i=0; i<1000;i++)
>         for(j=0; j<1000;j++)
>             for(k=0; k<10; k++)
>                 {
>                      dx++;
>                 }
>     DWORD end = timeGetTime();
> In C++ int and doubles. The C++ came back with a time of 15ms, and D came back with 45ms.

Are these tests with DMD vs. DMC, or GDC vs. GCC?  If you're using different compilers for the C++ and
D tests then you're really testing the code generator and optimizer more than the language.  D code
generated by DMD, for example, is notoriously slow at floating point operations, while the same code is
much faster with GDC.  This is an artifact of the Digital Mars back-end rather than the language itself.


Sean



More information about the Digitalmars-d mailing list