D speed compared to C++

BCS BCS at pathlink.com
Tue Mar 18 14:08:48 PDT 2008


Matthew Allen wrote:
> 
> 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.

first of all what C++ compiler? the best for testing would be DMC as 
that removes the back end differences.

Second how many test runs was that over?

third, try it with doubles (64bit reals) in both programs as the 
different conversions might be making a difference.

Another thing that might mask some stuff is start up time. Try running 
the test loops in another loop and spit out sequential times. I have 
seen large (2x - 3x) differences in the first run of a test vs. later 
runs. This would avoid random variables like the test code spanning a 
page boundary in one case and no in the other.

If you have done these things already then I don't known what's 
happening. /My/ next step would be to start looking at the ASM, but then 
again I'm known to be crazy.



More information about the Digitalmars-d mailing list