Slow performance compared to C++, ideas?

finalpatch fengli at gmail.com
Thu May 30 22:49:51 PDT 2013


Thanks Nazriel,

It is very cool you are able to narrow the gap to within 1.5x of 
c++ with a few simple changes.

I checked your version, there are 3 changes (correct me if i 
missed any):

* Change the (float) constructor from v= [x,x,x] to v[0] = x; 
v[1] = x; v[2] = x;
* Get rid of the (float[]) constructor and use 3 floats instead
* Change class methods to final

The first change alone shaved off 220ms off the runtime, the 2nd 
one cuts 130ms
and the 3rd one cuts 60ms.

Lesson learned: by very very careful about dynamic arrays.

On Friday, 31 May 2013 at 05:15:11 UTC, nazriel wrote:
> After few fast changes I manage to get such results:
> [raz at d3 tmp]$ ./a.out
> rendering time 276 ms
> [raz at d3 tmp]$ ./test
> 346 ms, 814 μs, and 5 hnsecs
>
>
> ./a.out being binary compiled with clang++ ./test.cxx 
> -std=c++11 -lSDL -O3
> ./test being binary compiled with ldmd2 -O3 -release -inline 
> -noboundscheck ./test.d (Actually I used rdmd with 
> --compiler=ldmd2 but I omitted it because it was rather long 
> cmd line :p)
>
>
> Here is source code with changes I applied to D-code (I hope 
> you don't mind repasting it): http://dpaste.dzfl.pl/84bb308d
>
> I am sure there is way more room for improvements and at 
> minimum achieving C++ performance.



More information about the Digitalmars-d mailing list