GDC vs dmd speed

Spacen Jasset spacenjasset at yahoo.co.uk
Tue Oct 15 15:38:44 PDT 2013


On 14/10/2013 22:06, bearophile wrote:
> Spacen Jasset:
>
>>     const float pi = 3.14159265f;
>>
>>     float dx = cast(float)(Clock.currSystemTick.length %
>> (TickDuration.ticksPerSec * 10)) / (TickDuration.ticksPerSec * 10);
>>     float xRot = sin(dx * pi * 2) * 0.4f + pi / 2;
>>     float yRot = cos(dx * pi * 2) * 0.4f;
>>     float yCos = cos(yRot);
>>     float ySin = sin(yRot);
>>     float xCos = cos(xRot);
>>     float xSin = sin(xRot);
>>
>>     float ox = 32.5f + dx * 64;
>>     float oy = 32.5f;
>>     float oz = 32.5f;
>>
>>     for (int x = 0; x < width; ++x) {
>>         float ___xd = cast(float)(x - width / 2) / height;
>>         for (int y = 0; y < height; ++y) {
>>             float __yd = cast(float)(y - height / 2) / height;
>>             float __zd = 1;
>
>
> The performance difference between the DMD and GDC compile is kind of
> expected for FP-heavy code. Also try the new LDC2 compiler (ldmd2 for
> the same compilation switches) that sometimes is better than GDC.
>
> More comments:
> - There is a PI in std.math (but it's not a float);
> - Add immutable/const to every variable that doesn't need to change.
> This is a good habit like washing your hands before eating;
> - "for (int x = 0; x < width; ++x)" ==> "foreach (immutable x; 0 ..
> width)";
> - I suggest to avoid many leading/trailing newlines in identifier names;
> - It's probably worth replacing all those "float" with another name,
> like "FP" and then define "alias FP = float;" at the beginning. So you
> can see how much performance you lose/gain using floats/doubles. In many
> cases in my code there is no difference, but float are less precise.
> Floats can be useful when you have many of them, in a struct or array.
> Floats can also be useful when you call certain numerical functions that
> compute their result by approximation, but on some CPUs sin/cos are not
> among those functions.
>
> Bye,
> bearophile
Thank you. I may take up some of those suggestions. It was a direct port 
of some c++ hence the style.


More information about the Digitalmars-d mailing list