D looses in speed to Common Lisp
Daniel Kozák via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 11 23:24:27 PDT 2015
On Mon, 11 May 2015 23:32:47 +0000
Dzhon Smit via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> 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.
This is wierd, you probably enable debug or I do not belive your
timing. Even with dmd (not ldc or gdc) I get better timing for D
idiomatic code than lisp version.
$ time sbcl --dynamic-space-size 4GB --script fib.lisp
0
real 0m2.263s
user 0m1.337s
sys 0m0.917s
[kozak at dajinka ~]$ dmd test.d
[kozak at dajinka ~]$ time ./test
0
real 0m1.883s
user 0m1.873s
sys 0m0.003s
[kozak at dajinka ~]$ ldc test.d
[kozak at dajinka ~]$ time ./test
0
real 0m1.311s
user 0m1.310s
sys 0m0.000s
[kozak at dajinka ~]$ gdc -o test test.d
[kozak at dajinka ~]$ time ./test
0
real 0m1.447s
user 0m1.440s
sys 0m0.003s
[kozak at dajinka ~]$ dmd -debug test.d
[kozak at dajinka ~]$ time ./test
0
real 0m3.816s
user 0m3.797s
sys 0m0.010s
More information about the Digitalmars-d
mailing list