D speed compared to C++

Koroskin Denis 2korden+dmd at gmail.com
Thu Mar 20 04:19:00 PDT 2008


On Thu, 20 Mar 2008 00:44:02 +0300, Matthew Allen  
<mallen at creativelifestyles.removeme.com> wrote:

> 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!!!
>


Obviously, you can not say that D integer increment is faster or slower  
than that of C++, it just doesn't depend on a language design. You could  
compare DMD to GCC and that would make similar sense to comparison of GCC  
and, say, ICC or DMC. The difference is a matter of optimization  
techniques used be the language compilers, not by languages. Surely,  
higher level language design makes some inpact on general performance,  
like GC or constant-time array slicing, but not low level variable  
increments/loops etc.. General D performance would only increase as more  
vendors will produce commercial D compilers.



More information about the Digitalmars-d mailing list