DMD floating point performance.

Dave Dave_member at pathlink.com
Sat Nov 11 21:51:27 PST 2006


Ok this is trivial, but it probably fairly represents what many use floating point for day-to-day 
(simple math on simple data):

import std.stdio, std.date;

void main()
{
     d_time s = getUTCtime;
     double sum = 1.0, val = 1.000001;
     for(size_t i = 0; i < 10_000_000; i++)
     {
         sum += val;
         sum -= val;
         sum *= val;
         sum /= val;
     }
     d_time e = getUTCtime;
     writefln(sum,": ",(e-s)/cast(real)TicksPerSecond," secs");
}

# gdc -O2 fp.d -o fp ; fp
1: 0.282 secs

# dmd -O fp.d ; fp
1: 0.683 secs

A difference of 2.5x?!

If you look at the DMD asm, the problem is that each operation is wrapped by a load/store.. Why 
wouldn't val and sum be kept in fp registers inside the loop?

Another couple of examples: http://shootout.alioth.debian.org/gp4/benchmark.php?test=mandelbrot&lang=all
http://shootout.alioth.debian.org/gp4/benchmark.php?test=nbody&lang=all

I mean I'd like to standardize on DMD; a) it doesn't come with any baggage on either Windows or 
Linux and b) it is more consistently maintained as of late, but things like this make the decision a 
lot tougher.

Thanks,

- Dave



More information about the Digitalmars-d mailing list