D looses in speed to Common Lisp

Dzhon Smit via Digitalmars-d digitalmars-d at puremagic.com
Mon May 11 16:32:47 PDT 2015


On Monday, 11 May 2015 at 22:22:23 UTC, anonymous wrote:
> On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote:
>> Tests on my machine:
>> [code]$ time ./fib
>> 0
>>
>> real    0m6.458s
>> user    0m2.250s
>> sys     0m0.933s
>> $ time sbcl --dynamic-space-size 4GB --script fib.lisp
>> 0
>>
>> real    0m1.884s
>> user    0m1.290s
>> sys     0m0.260s[/code]
>
> Can't confirm that. Times for me (linux x86_64):
>
> ----
> $ dmd fib.d && time ./fib
> 0
>
> real    0m2.410s
> user    0m1.844s
> sys     0m0.558s
>
> $ time sbcl --dynamic-space-size 4GB --script fib.lisp
> 0
>
> real    0m2.659s
> user    0m2.144s
> sys     0m0.506s
> ----
>
> As usual, ldc produces a faster binary than dmd:
>
> ----
> $ ldc2 fib.d && time ./fib
> 0
>
> real    0m1.900s
> user    0m1.396s
> sys     0m0.499s
> ----
>
> Optimization flags don't seem to matter much for this program.

Could you re-run sbcl?  The first time it runs it creates fasls, 
and afterwards it reuses them.  Probably you shouldn't include 
the compile time for dmd either.

> import std.stdio, std.bigint;
> import std.range;
> import std.algorithm;
> 
> void main() {
> 
>     int n = 100000;
>     auto sumFib1 = recurrence!("a[n-1] + a[n-2]")(BigInt(0),
>             BigInt(1)).take(n).sum;
>     auto sumFib2 = recurrence!("a[n-1] + a[n-2]")(BigInt(0),
>             BigInt(1)).take(n).sum;
> 
>     writeln(sumFib2 - sumFib1); // 0
> }

The point was to compare the performance of nearly identical 
pieces of code in D and in CL.  However, when I compile this 
idiomatic sample with `dmd fib2`, I get

$ time ./fib2
0

real    0m2.226s
user    0m2.223s
sys     0m0.003s

which is still slower.


More information about the Digitalmars-d mailing list