2 ms·
SBCL on my 2012 Mac mini: rjmacmini:~$ sbcl This is SBCL 1.4.2, an implementation of ANSI Common Lisp. More information about SBCL is available at
by lispm 8y ago
SBCL on my 2012 Mac mini:
rjmacmini:~$ sbcl
This is SBCL 1.4.2, an implementation of ANSI Common Lisp.
More information about SBCL is available at <http://www.sbcl.org/>.
SBCL is free software, provided as is, with absolutely no warranty.
It is mostly in the public domain; some portions are provided under
BSD-style licenses. See the CREDITS and COPYING files in the
distribution for more information.
* (defun fib (n)
(declare (fixnum n)
(optimize (speed 3) (debug 0) (safety 0)))
(if (<= n 1)
1
(the fixnum
(+ (fib (- n 1))
(fib (- n 2))))))
FIB
* (time (fib 46))
Evaluation took:
14.957 seconds of real time
14.947616 seconds of total run time (14.934818 user, 0.012798 system)
99.94% CPU
38,799,794,836 processor cycles
0 bytes consed
2971215073
* (SAVE-LISP-AND-DIE "/tmp/fiblisp" :toplevel (lambda (&rest args) (print (fib 46))) :executable t)
; in: SAVE-LISP-AND-DIE "/tmp/fiblisp"
; (LAMBDA (&REST ARGS) (PRINT (FIB 46)))
;
; caught STYLE-WARNING:
; The variable ARGS is defined but never used.
;
; compilation unit finished
; caught 1 STYLE-WARNING condition
[undoing binding stack and other enclosing state... done]
[defragmenting immobile space... 643+15263+734+344+25029+16756 objects... done]
[saving current Lisp image into /tmp/fiblisp:
writing 0 bytes from the read-only space at 0x20000000
writing 848 bytes from the static space at 0x20100000
writing 1863680 bytes from the immobile space at 0x20300000
writing 11472480 bytes from the immobile space at 0x21b00000
writing 26542080 bytes from the dynamic space at 0x1000000000
done]
rjmacmini:~$ time /tmp/fiblisp
2971215073
real 0m14.785s
user 0m14.755s
sys 0m0.020s
rjmacmini:~$
- stevelosh 8y agoI don't think adding debug/safety 0 are really worth it. In this: (declaim (optimize speed) (ftype (function (fixnum) fixnum) fib)) (defun fib (n) (if (<= n 1) 1 (+ (fib (- n 1)) (fib (- n 2))))) (print (fib 46)) adding `(safety 0) (debug 0)` took the time from 13.17s (with just the `speed` declaration) down to 12.94s for me. Is a 2% speed increase really worth the danger of `(safety 0)`?
- lispm 8y agoGenerally depends on the implementation and the default behavior. But anyway, it's a good point.