D looses in speed to Common Lisp
Dennis Ritchie via Digitalmars-d
digitalmars-d at puremagic.com
Mon May 11 16:03:25 PDT 2015
On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote:
> Just in case you wonder, here's a comparison of the Fibonacci
> numbers. The D code was written by Dennis Ritchie (a user of
> this forum, not the guy who invented C).
>
> [code]import std.stdio, std.bigint;
>
> void main() {
>
> BigInt[] fib1, fib2;
> BigInt last = 0, next = 1;
>
> int n = 100000;
>
> int i;
> while (i != n) {
> fib1 ~= last, last = next, next += fib1[$ - 1];
> ++i;
> }
>
> i = 0, last = 0, next = 1;
> while (i != n) {
> fib2 ~= last, last = next, next += fib2[$ - 1];
> ++i;
> }
>
> BigInt sumFib1;
> foreach (e; fib1) {
> sumFib1 += e;
> }
>
> BigInt sumFib2;
> foreach (e; fib2) {
> sumFib2 += e;
> }
>
> writeln(sumFib2 - sumFib1); // 0
> }[/code]
> [code];;;; fib.lisp
> (defun main ()
> (let ((n 100000))
> (let ((fib1 (do ((i 0 (incf i))
> (last 0 next)
> (next 1 (+ next last))
> (fib '() (cons last fib)))
> ((= i n) (nreverse fib))))
> (fib2 (do ((i 0 (incf i))
> (last 0 next)
> (next 1 (+ next last))
> (fib '() (cons last fib)))
> ((= i n) (nreverse fib)))))
> (let ((sum-fib-1 (loop :for e :in fib1 :sum e))
> (sum-fib-2 (loop :for e :in fib2 :sum e)))
> (- sum-fib-2 sum-fib-1)))))
>
> (format t "~D~%" (main))[/code]
>
> 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]
It's some kind of stuffing the community Lisp programmers who try
to prove that SBSL faster than D. Nothing like that.
More information about the Digitalmars-d
mailing list