[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Chicken-users] benchmark mode misteries

From: Michele Simionato
Subject: [Chicken-users] benchmark mode misteries
Date: Sat, 1 Mar 2008 08:20:47 +0000 (UTC)
User-agent: Loom/3.14 (

I was doing some benchmarking the other day and I am puzzled by the following
factorial benchmark:

(define (call n proc . args)
  (let loop ((i 0))
    (when (< i n) (apply proc args) (loop (+ 1 i)))))

(define (fac x)
  (if (= x 0) 1
      (* x (fac (- x 1)))))

(define n
  (string->number (car (reverse (argv)))))

(time (call 10000000 (lambda () (fac n)))); works for n<13
(display "result:") (display (fac n)) (newline)

This is extremely fast:

$ csc -Ob fact.scm
$ ./fact 7   
0.176 seconds elapsed       
0 seconds in (major) GC
       0 mutations
       1 minor GCs
       0 major GCs

This is CHICKEN Version 2.732 on macosx-unix-gnu-x86.

OTOH, if I change a single line and I replace

(call 10000000 (lambda () (fac n)))


(call 10000000 fac n)

my programs runs ten times slower:

 ./fact 7
   1.631 seconds elapsed
   0.011 seconds in (major) GC
       0 mutations
    1881 minor GCs
      23 major GCs

All the time is spent in garbage collection.
I am just curious to know which optimization I am breaking and
why the compiler cannot be smart enough. Any idea? 

           Michele Simionato

reply via email to

[Prev in Thread] Current Thread [Next in Thread]