I managed to get it even faster.
[raz@d3 tmp]$ ./a.out
rendering time 282 ms
[raz@d3 tmp]$ ./test
202 ms, 481 μs, and 8 hnsecs
So D version is 1,4x faster than C++ version.
At least on my computer.
Same compilers flags etc
Final code:
http://dpaste.dzfl.pl/61626e88
I guess there is still more room for improvements.
On Friday, 31 May 2013 at 05:49:55 UTC, finalpatch wrote:
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;
Correct
* Get rid of the (float[]) constructor and use 3 floats instead
It was just for debbuging so compiler would yell at me if I use
array literal
* Change class methods to final
Correct
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.
Yeah, it is currently a problem with array literals. They're
always allocated on heap even if they shouldn't be.
Final before methods is something that needs to be remembered