D looses in speed to Common Lisp
Daniel Kozak via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 11 15:01:39 PDT 2015
On Mon, 11 May 2015 21:38:10 +0000 (UTC)
Justin Whear via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> All those allocations aren't helping. Here's a much more idiomatic D
> version:
>
> import std.stdio, std.bigint;
> import std.range;
> void main() {
> int n = 100000;
> auto fib1 = recurrence!("a[n-1] + a[n-2]")(BigInt(0), BigInt
> (1)).takeExactly(n);
> auto fib2 = recurrence!("a[n-1] + a[n-2]")(BigInt(0), BigInt
> (1)).takeExactly(n);
>
> BigInt sumFib1;
> foreach (e; fib1)
> sumFib1 += e;
>
> BigInt sumFib2;
> foreach (e; fib2)
> sumFib2 += e;
>
> writeln(sumFib2 - sumFib1); // 0
> }
>
> Timing on my box:
> $ time ./fib
> 0
>
> real 0m1.520s
> user 0m1.520s
> sys 0m0.000s
>
> Compiling with `ldmd2 fib.d -inline -noboundscheck -O -release`:
> $ time ./fib
> 0
>
> real 0m0.784s
> user 0m0.776s
> sys 0m0.000s
Yep, this is what come to my mind when I read OP
More information about the Digitalmars-d
mailing list