D speed compared to C++
Walter Bright
newshound1 at digitalmars.com
Tue Mar 18 15:02:32 PDT 2008
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.
More information about the Digitalmars-d
mailing list