[gambit-list] compiling fib

Bradley Lucier lucier at math.purdue.edu
Fri Jan 21 13:59:42 EST 2011


<Explanation by Marc about padding in call frames deleted.>

Ah, so this is the cost that all calls incur in Gambit so that one can
implement call/cc?

I thought of this when perusing

http://translate.google.com/translate?js=n&prev=_t&hl=en&ie=UTF-8&layout=2&eotf=1&sl=auto&tl=en&u=http%3A%2F%2Fcall-with-hopeless-continuation.blogspot.com%2F2010%2F03%2Flies-damn-lies-and-benchmarks.html

(apologies to those who understand the original Italian).  The guy says
that he wrote the C code

include <stdio.h>

int fib (int n) {
  if (n == 0 || n == 1) {
    return n;
  } else {
    return fib(n - 1) + fib(n - 2);
  }
}

int main() {
  int n;
  for (n = 0; n < 40; n++) {
    printf ("fib(%d)=%d\n", n, fib(n));
  }
  return 0;
}

and the scheme code

declare (standard-bindings)
	 (extended-bindings)
	 (block)
	 (not safe))

(define (fib n)
  (if (or (fx= n 0)
	  (fx= n 1))
      n
      (fx+ (fib (fx- n 1))
	   (fib (fx- n 2)))))

(do ((n 0 (fx+ n 1)))
    ((fx= n 40))
  (for-each display
	    (list "fib(" n ")=" (fib n) #\newline)))

and on his box Chicken ran the Scheme code (at -O5 compilation level)
faster than the C code with

gcc -O3 -W -Wall -o fib_c fib_c.c

On my box, I don't have chicken installed, but

heine:~> time ./fib_c
1.490u 0.000s 0:01.49 100.0%	0+0k 0+0io 0pf+0w

and after compilation

heine:~> time gsi fib_scm
4.860u 0.010s 0:04.87 100.0%	0+0k 0+0io 0pf+0w

So, it looks like Chicken really smokes Gambit on this femtobenchmark.
The question is, should it?

(I suppose you'll come back with benchmarks using your native x86-32
back end at this point, but I need to run 64-bit Gambit ...)

Brad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.iro.umontreal.ca/pipermail/gambit-list/attachments/20110121/8f9e263f/attachment.htm>


More information about the Gambit-list mailing list