www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - D looses in speed to Common Lisp

reply "Dzhon Smit" <dzhon smit.ds> writes:
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]

[quote]Email address

When posting, you need to indicate an email address. It doesn't 
need to be a valid one; this software will not send anything to 
the specified address. The email address will be made public to 
other users of the news server / mailing list you are posting to. 
Therefore, please be aware that malicious robots may be able to 
collect your address and send spam to it.[/quote]

This is quite disappointing, I'd prefer spam from this forum 
rather than from elsewhere.
May 11 2015
next sibling parent reply "weaselcat" <weaselcat gmail.com> writes:
On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote:
 ...
time sbcl --dynamic-space-size 4GB --script fib.lisp 0 1.16user 1.49system 0:02.67elapsed 99%CPU (0avgtext+0avgdata 1658860maxresident)k ldc -O5 -release -boundscheck=off fib.d $ time ./fib 0 1.33user 0.81system 0:02.15elapsed 99%CPU (0avgtext+0avgdata 1230712maxresident)k
May 11 2015
next sibling parent "weaselcat" <weaselcat gmail.com> writes:
On Monday, 11 May 2015 at 21:30:20 UTC, weaselcat wrote:
 On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote:
 ...
time sbcl --dynamic-space-size 4GB --script fib.lisp 0 1.16user 1.49system 0:02.67elapsed 99%CPU (0avgtext+0avgdata 1658860maxresident)k ldc -O5 -release -boundscheck=off fib.d $ time ./fib 0 1.33user 0.81system 0:02.15elapsed 99%CPU (0avgtext+0avgdata 1230712maxresident)k
oh, and if you make the arrays static it should be turned into CTFE.
May 11 2015
prev sibling parent maarten van damme via Digitalmars-d <digitalmars-d puremagic.com> writes:
It may be a good idea to prealocate the whole array so you don't resize the
dynamic arrays every execution of the loop.

2015-05-11 23:30 GMT+02:00 weaselcat via Digitalmars-d <
digitalmars-d puremagic.com>:

 On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote:

 ...
time sbcl --dynamic-space-size 4GB --script fib.lisp 0 1.16user 1.49system 0:02.67elapsed 99%CPU (0avgtext+0avgdata 1658860maxresident)k ldc -O5 -release -boundscheck=off fib.d $ time ./fib 0 1.33user 0.81system 0:02.15elapsed 99%CPU (0avgtext+0avgdata 1230712maxresident)k
May 11 2015
prev sibling next sibling parent reply Justin Whear <justin economicmodeling.com> writes:
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
May 11 2015
parent Daniel Kozak via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Mon, 11 May 2015 21:38:10 +0000 (UTC)
Justin Whear via Digitalmars-d <digitalmars-d 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
May 11 2015
prev sibling next sibling parent Daniel Kozak via Digitalmars-d <digitalmars-d puremagic.com> writes:
On Mon, 11 May 2015 21:15:31 +0000
Dzhon Smit via Digitalmars-d <digitalmars-d puremagic.com> 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]
 
 [quote]Email address
 
 When posting, you need to indicate an email address. It doesn't 
 need to be a valid one; this software will not send anything to 
 the specified address. The email address will be made public to 
 other users of the news server / mailing list you are posting to. 
 Therefore, please be aware that malicious robots may be able to 
 collect your address and send spam to it.[/quote]
 
 This is quite disappointing, I'd prefer spam from this forum 
 rather than from elsewhere.
On my machine this is much faster 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 }
May 11 2015
prev sibling next sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
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]

 [quote]Email address

 When posting, you need to indicate an email address. It doesn't 
 need to be a valid one; this software will not send anything to 
 the specified address. The email address will be made public to 
 other users of the news server / mailing list you are posting 
 to. Therefore, please be aware that malicious robots may be 
 able to collect your address and send spam to it.[/quote]

 This is quite disappointing, I'd prefer spam from this forum 
 rather than from elsewhere.
Turns out you can write slow code in any language. Who knew?
May 11 2015
prev sibling next sibling parent reply "anonymous" <anonymous example.com> writes:
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.
May 11 2015
next sibling parent reply "Dzhon Smit" <dzhon smit.ds> writes:
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.
May 11 2015
next sibling parent reply "Laeeth Isharc" <nospamlaeeth nospam.laeeth.com> writes:
On Monday, 11 May 2015 at 23:32:48 UTC, Dzhon Smit wrote:

 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.
we already know dmd doesn't produce the fastest code, and obviously you are not comparing languages but a complex set of things particularly compilers. nobody who cares about performance will stick with dmd without trying alternatives (and these are free, readily available alternatives not special things you need to pay a fortune for as with some of the 'java GC can be realtime' guys argued indicated as having relevance to the commercial choice in ordinary circumstances to use java or not). if one wanted to spend a couple hundred k bucks on rewriting the codegen, I am sure you would see dmd fast again, but what would that demonstrate about D the language? it's fair play to compare naive code using fast compilers, but just like micro benchmarks, one shouldn't make more of the result than may be justified. ie the real question is in practical use cases (bearing in mind you are going to pick one or two languages and stick with them, figuring out the tricks with experience), given reasonable effort, what is relative performance like? and I doubt anyone is going to not use D because "it's slower than common lisp". what I have read of the facebook experience (although hardly a controlled experiment by a neutral observer) is intriguing from that perspective.
May 11 2015
parent "Laeeth Isharc" <nospamlaeeth nospam.laeeth.com> writes:
On Tuesday, 12 May 2015 at 01:20:13 UTC, Laeeth Isharc wrote:
 On Monday, 11 May 2015 at 23:32:48 UTC, Dzhon Smit wrote:

 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.
ie, especially post internet, one has a responsibility for the effect one's words have on the world because they will be read by potentially many people that don't have the context to hand and take things literally.
May 11 2015
prev sibling next sibling parent Daniel =?UTF-8?B?S296w6Fr?= via Digitalmars-d writes:
On Mon, 11 May 2015 23:32:47 +0000
Dzhon Smit via Digitalmars-d <digitalmars-d 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 dajinka ~]$ dmd test.d [kozak dajinka ~]$ time ./test 0 real 0m1.883s user 0m1.873s sys 0m0.003s [kozak dajinka ~]$ ldc test.d [kozak dajinka ~]$ time ./test 0 real 0m1.311s user 0m1.310s sys 0m0.000s [kozak dajinka ~]$ gdc -o test test.d [kozak dajinka ~]$ time ./test 0 real 0m1.447s user 0m1.440s sys 0m0.003s [kozak dajinka ~]$ dmd -debug test.d [kozak dajinka ~]$ time ./test 0 real 0m3.816s user 0m3.797s sys 0m0.010s
May 11 2015
prev sibling parent "anonymous" <anonymous example.com> writes:
On Monday, 11 May 2015 at 23:32:48 UTC, Dzhon Smit wrote:
 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.
Sure thing. I think that wasn't the first run already. But to make sure, I just ran it all again. The D version here is the original you posted. ---- $ time sbcl --dynamic-space-size 4GB --script fib.lisp 0 real 0m3.181s user 0m1.814s sys 0m0.459s $ time sbcl --dynamic-space-size 4GB --script fib.lisp 0 real 0m2.256s user 0m1.828s sys 0m0.423s $ dmd fib.d && time ./fib 0 real 0m2.227s user 0m1.714s sys 0m0.507s $ ldc2 fib.d && time ./fib 0 real 0m1.688s user 0m1.341s sys 0m0.343s ----
May 12 2015
prev sibling parent "John Colvin" <john.loughran.colvin gmail.com> writes:
On Monday, 11 May 2015 at 22:22:23 UTC, anonymous wrote:
 Optimization flags don't seem to matter much for this program.
Most of the bigint work is probably happening in handwritten assembly code and the memory allocation code is compiled in to druntime, so the optimiser isn't really getting much important to work on.
May 12 2015
prev sibling next sibling parent "Dennis Ritchie" <dennis.ritchie mail.ru> writes:
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.
May 11 2015
prev sibling next sibling parent reply "bachmeier" <no spam.net> writes:
On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote:

Seems this:

--dynamic-space-size 4GB

is pretty important. I don't have that much RAM on my Chromebook 
so I removed it. It dies quickly with the error

Heap exhausted during garbage collection: 1408 bytes available, 
2240 requested.

I'm guessing that your code is not doing the same thing as the D 
code if you have to use tricks like that just to get it to run. 
Having used Common Lisp, I know your program requires extensive 
knowledge of the language, and was the result of a careful 
optimization exercise - unlike the D code. It's definitely not 
the kind of code you'd write after reading Practical Common Lisp.
May 11 2015
next sibling parent "Chris" <wendlec tcd.ie> writes:
On Tuesday, 12 May 2015 at 01:48:58 UTC, bachmeier wrote:
 On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote:

 Seems this:

 --dynamic-space-size 4GB

 is pretty important. I don't have that much RAM on my 
 Chromebook so I removed it. It dies quickly with the error

 Heap exhausted during garbage collection: 1408 bytes available, 
 2240 requested.

 I'm guessing that your code is not doing the same thing as the 
 D code if you have to use tricks like that just to get it to 
 run. Having used Common Lisp, I know your program requires 
 extensive knowledge of the language, and was the result of a 
 careful optimization exercise - unlike the D code. It's 
 definitely not the kind of code you'd write after reading 
 Practical Common Lisp.
Thanks for this bit of information.
May 12 2015
prev sibling parent reply Marco Leise <Marco.Leise gmx.de> writes:
Am Tue, 12 May 2015 01:48:57 +0000
schrieb "bachmeier" <no spam.net>:

 On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote:
 
 Seems this:
 
 --dynamic-space-size 4GB
 
 is pretty important. I don't have that much RAM on my Chromebook 
 so I removed it. It dies quickly with the error
 
 Heap exhausted during garbage collection: 1408 bytes available, 
 2240 requested.
 
 I'm guessing that your code is not doing the same thing as the D 
 code if you have to use tricks like that just to get it to run. 
 Having used Common Lisp, I know your program requires extensive 
 knowledge of the language, and was the result of a careful 
 optimization exercise - unlike the D code. It's definitely not 
 the kind of code you'd write after reading Practical Common Lisp.
I don't know LISP, but I find no trace of appending numbers to a temporary dynamic array in the LISP code. If so, from an algorithmic point of view Daniel Kozak's version is the most spot-on translation of the original. The idea behind porting code between languages as different as D and LISP should not be to replicate the computational work while staying true to the target language. Similar looks wont get you there. -- Marco
May 12 2015
parent "bachmeier" <no spam.net> writes:
On Tuesday, 12 May 2015 at 10:03:16 UTC, Marco Leise wrote:
 Am Tue, 12 May 2015 01:48:57 +0000
 schrieb "bachmeier" <no spam.net>:

 On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote:
 
 Seems this:
 
 --dynamic-space-size 4GB
 
 is pretty important. I don't have that much RAM on my 
 Chromebook so I removed it. It dies quickly with the error
 
 Heap exhausted during garbage collection: 1408 bytes 
 available, 2240 requested.
 
 I'm guessing that your code is not doing the same thing as the 
 D code if you have to use tricks like that just to get it to 
 run. Having used Common Lisp, I know your program requires 
 extensive knowledge of the language, and was the result of a 
 careful optimization exercise - unlike the D code. It's 
 definitely not the kind of code you'd write after reading 
 Practical Common Lisp.
I don't know LISP, but I find no trace of appending numbers to a temporary dynamic array in the LISP code. If so, from an algorithmic point of view Daniel Kozak's version is the most spot-on translation of the original. The idea behind porting code between languages as different as D and LISP should not be to replicate the computational work while staying true to the target language. Similar looks wont get you there.
The main point in posting that was to show that the program doesn't even run without an SBCL-specific command line option. I'm not going to dig into this because it's a silly example. However, my guess is that it has to do with this: (fib '() (cons last fib)) That creates a new cons each time through. Reserving 4 GB probably allows the program to avoid the garbage collector. I'm assuming that the other part of the performance story is this: (loop :for e :in fib2 :sum e) where the sum is almost certainly optimized, so the benchmark doesn't measure the speed of CL anyway, only the ability of the SBCL compiler developers to write optimized code that covers a handful of common cases.
May 12 2015
prev sibling parent reply "Vladimir Panteleev" <vladimir thecybershadow.net> writes:
On Monday, 11 May 2015 at 21:15:33 UTC, Dzhon Smit wrote:
 [quote]Email address

 When posting, you need to indicate an email address. It doesn't 
 need to be a valid one; this software will not send anything to 
 the specified address. The email address will be made public to 
 other users of the news server / mailing list you are posting 
 to. Therefore, please be aware that malicious robots may be 
 able to collect your address and send spam to it.[/quote]

 This is quite disappointing, I'd prefer spam from this forum 
 rather than from elsewhere.
There is no way around this if you want your message to reach NNTP and mailing list users, which are about half of the posters here. The relevant protocols require a valid-looking email address in the "From" header. As the help text says, the address doesn't need to be actually valid.
May 12 2015
parent "anonymous" <anonymous example.com> writes:
On Tuesday, 12 May 2015 at 14:58:40 UTC, Vladimir Panteleev wrote:
 There is no way around this if you want your message to reach 
 NNTP and mailing list users, which are about half of the 
 posters here. The relevant protocols require a valid-looking 
 email address in the "From" header. As the help text says, the 
 address doesn't need to be actually valid.
You could default to a specific address, though, like anything example.com or noreply forum.dlang.org. Reducing the work for poor Elsa over at <http://invalid.com>.
May 12 2015