Slow performance compared to C++, ideas?

finalpatch fengli at gmail.com
Thu May 30 22:58:57 PDT 2013


You guys are awesome! I am happy to know that D can indeed offer 
comparable speed to C++.

But it also shows there is room for the compiler to improve as 
the C++ version also makes heavy use of loops (or STL algorithms) 
but they get inlined or unrolled automatically.

On Friday, 31 May 2013 at 05:35:58 UTC, Juan Manuel Cabo wrote:
> You might also try changing:
>
>             float[3] t = mixin("v[]"~op~"rhs.v[]");
>             return Vec3(t[0], t[1], t[2]);
>
> for:
>             Vec3 t;
>             t.v[0] = mixin("v[0] "~op~" rhs.v[0]");
>             t.v[1] = mixin("v[1] "~op~" rhs.v[1]");
>             t.v[2] = mixin("v[2] "~op~" rhs.v[2]");
>             return t;
>
> and so on, avoiding the float[3] and the v[] operations (which 
> would
> loop, unless the compiler/optimizer unrolls them (didn't 
> check)).
>
> I tested this change (removing v[] ops) in Vec3 and in
> normalize(), and it made your version slightly faster
> with DMD (didn't check with ldmd2).
>
> --jm



More information about the Digitalmars-d mailing list