Language Shootout

Don Clugston dac at nospam.com.au
Mon Mar 26 23:59:45 PDT 2007


David B. Held wrote:
> Dave wrote:
>> Dan Wrote:
>>
>>> Hi guys,
>>>
>>> This idea will only work with Walter in on it.  : p  I was thinking 
>>> that we might go through the various benchmarks in "the language 
>>> shootout" and find out those items where D is significantly behind 
>>> for any reason, and correct the performance.
>>>
>>> For example, against Eiffel, you see their Fasta implementation is 38 
>>> times faster than D's.  Why not compile the code, find out how it 
>>> works and see why D's that much slower - and then Walter can fix the 
>>> code?
>>>
>>
>> Huh? D is a tad better on one machine and just a bit slower on the 
>> other machine (on the Shootout). Maybe there was some sort of problem 
>> on the site when you looked at it?
>>
>> http://shootout.alioth.debian.org/gp4/benchmark.php?test=fasta&lang=all
>>
>> http://shootout.alioth.debian.org/debian/benchmark.php?test=fasta&lang=all 
>>
> 
> In fact, the D version is written nicely, but the the fastest C++ 
> version is clearly written for speed.  I'm willing to bet that D could 
> close the gap by taking away all classes and using free functions + 
> structs the way the C++ version does.  Anybody up for it?  Since we 
> can't test on the shootout machine itself, improvements should be 
> measured relative to the currently published version.

Try changing the constants in the Random class to be 'const double' 
instead of 'const int'. Mixing ints and doubles is really slow.

Try replacing the Random class with:

double genRandom(double max)
{
    static double seed = 42;
    const double IA = 3877, IC = 29573, IM = 139968;

    return max * ((seed = (seed * IA + IC) % IM) * (1.0 / IM));
}



More information about the Digitalmars-d mailing list