D speed compared to C++

Matthew Allen mallen at creativelifestyles.removeme.com
Wed Mar 19 14:44:02 PDT 2008


Walter Bright Wrote:

> Matthew Allen wrote:
> > 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.
> 
> Loop unrolling could be a big issue here. DMD doesn't do loop unrolling, 
> but that is not a language issue at all, it's an optimizer issue. It's 
> easy enough to check - get the assembler output of the loop from your 
> compiler and post it here.


Walter you are right. That was the issue. I added a function call into the loop and D came out a lot faster than C++. 

Thanks for a great language!!!




More information about the Digitalmars-d mailing list