Iain Little <lirvon@yahoo.com> wrote:
+---------------
| Pascal Costanza <costanza@web.de> writes:
| > (defun run ()
| > (time
| > (eval
| > '(labels ((fib (x)
| > (if (< x 2)
| > 1
| > (+
| > (fib (- x 2))
| > (fib (1- x))))))
| > (fib 41)))))
|
| Just because you are constructing a function at runtime, doesn't mean
| that you can't compile it...
|
| (time
| (eval '(funcall (compile (defun fib (x)
| (declare (optimize (speed 3) (safety 0) (debug 0))
| (type fixnum x))
| (if (< x 2)
| 1
| (+ (fib (- x 2))
| (fib (1- x))))))
| 41)))
|
| With CMUCL on an Athlon XP 1700:
|
| Evaluation took:
| 11.12 seconds of real time
| 11.12 seconds of user run time
| 0.0 seconds of system run time
| 0 page faults and
| 184696 bytes consed.
+---------------
I didn't see the original test code, but both of those look *awefully*
wasteful to this CL newbie. CMUCL's "time" is a macro, and automatically
compiles top-level forms anyway, so on my Athlon XP 1600+ (1.4 Gz) here's
what I get (with a few more declarations to get rid of the remaining
compiler warnings):
cmu> (time (labels ((fib (x)
(declare (optimize (speed 3) (safety 0)
(debug 0))
(type fixnum x))
(the fixnum
(if (< x 2)
1
(+ (the fixnum (fib (- x 2)))
(the fixnum (fib (1- x))))))))
(fib 41)))
; Compiling LAMBDA NIL:
; Compiling Top-Level Form:
; Evaluation took:
[*]==> ; 9.75 seconds of real time
; 9.705533 seconds of user run time
; 0.021392 seconds of system run time
; 13,708,807,468 CPU cycles
; 0 page faults and
; 64 bytes consed.
;
267914296
cmu>
-Rob
-----
Rob Warnock, PP-ASEL-IA <rpw3@rpw3.org>
627 26th Avenue <URL:http://rpw3.org/>
San Mateo, CA 94403 (650)572-2607