--- /dev/null
+
+(defun fib-1 (n)
+ "Borrowed from http://www.cliki.net/fibonacci"
+ (loop for f1 = 0 then f2
+ and f2 = 1 then (+ f1 f2)
+ repeat n finally (return f1)))
+
+(defun fib-2 (n)
+ (let ((f1 0) (f2 1) (n n))
+ (declare (:int f1 f2 n))
+ (ffi:c-progn (n f1 f2) "
+ int aux = 0;
+ for( ; #0>0; #0--, aux=#1) {
+ #1 = #2;
+ #2 = aux + #2;
+ }")
+ f1))
+
+(defun bench ()
+ (compile 'fib-1)
+ (compile 'fib-2)
+ (prog1 nil
+ (print "Common Lisp:")
+ (time (dotimes (x 10000000) (fib-1 20)))
+ (print "Common Lisp with inlined C:")
+ (time (dotimes (x 10000000) (fib-2 20)))))
+
+#|
+On my computer this yields:
+
+"Common Lisp:"
+real time : 9.583 secs
+run time : 9.596 secs
+gc count : 1 times
+consed : 271531840 bytes
+
+"Common Lisp with inlined C:"
+real time : 0.657 secs
+run time : 0.656 secs
+gc count : 1 times
+consed : 271567088 bytes
+
+Exercise: also try the first function with proper Lisp optimizations
+
+|#
--- /dev/null
+
+(defparameter
+ *simple-vector-characters*
+ '((#\a (((-2 2) (-2 -1) (-1 -2) (1 -2) (2 -1) (2 2))
+ ((-2 0) (2 0))))
+ (#\b (((-2 2) (-2 -2) (1 -2) (2 -1) (1 0) (-2 0) (1 0) (2 1) (1 2)
+ (-2 2))))
+ (#\c (((2 -1) (1 -2) (-1 -2) (-2 -1) (-2 1) (-1 2) (1 2) (2 1))))
+ (#\d (((-2 2) (-2 -2) (1 -2) (2 -1) (2 1) (1 2) (-2 2))))
+ (#\e (((2 -2) (-2 -2) (-2 2) (2 2))
+ ((-2 0) (1 0))))
+ (#\f (((2 -2) (-2 -2) (-2 2))
+ ((-2 0) (1 0))))
+ (#\g (((1 -2) (-1 -2) (-2 -1) (-2 1) (-1 2) (1 2) (2 1) (1 0) (0 0))))
+ (#\h (((-2 -2) (-2 2))
+ ((2 -2) (2 2))
+ ((-2 0) (2 0))))
+ (#\i (((0 -2) (0 2))
+ ((-1 -2) (1 -2))
+ ((-1 2) (1 2))))
+ (#\j (((1 -2) (1 1) (0 2) (-1 2) (-2 1))
+ ((0 -2) (2 -2))))
+ (#\k (((-2 -2) (-2 2))
+ ((2 -2) (-2 0) (2 2))))
+ (#\l (((-2 -2) (-2 2) (2 2))))
+ (#\m (((-2 2) (-2 -2) (0 0) (2 -2) (2 2))))
+ (#\n (((-2 2) (-2 -2) (2 2) (2 -2))))
+ (#\o (((-1 -2) (1 -2) (2 -1) (2 1) (1 2) (-1 2) (-2 1) (-2 -1)
+ (-1 -2))))
+ (#\p (((-2 2) (-2 -2) (1 -2) (2 -1) (1 0) (-2 0))))
+ (#\q (((-1 -2) (1 -2) (2 -1) (2 1) (1 2) (-1 2) (-2 1) (-2 -1) (-1 -2))
+ ((1 1) (2 2))))
+ (#\r (((-2 2) (-2 -2) (1 -2) (2 -1) (1 0) (-2 0))
+ ((1 0) (2 1) (2 2))))
+ (#\s (((2 -2) (-1 -2) (-2 -1) (-1 0) (1 0) (2 1) (1 2) (-2 2))))
+ (#\t (((0 -2) (0 2))
+ ((-2 -2) (2 -2))))
+ (#\u (((-2 -2) (-2 1) (-1 2) (1 2) (2 1) (2 -2))))
+ (#\v (((-2 -2) (0 2) (2 -2))))
+ (#\w (((-2 -2) (-2 2) (0 0) (2 2) (2 -2))))
+ (#\x (((2 -2) (-2 2))
+ ((-2 -2) (2 2))))
+ (#\y (((0 0) (0 2))
+ ((-2 -2) (0 0) (2 -2))))
+ (#\z (((-2 -2) (2 -2) (-2 2) (2 2))))
+ (#\0 (((-1 -2) (1 -2) (2 -1) (2 1) (1 2) (-1 2) (-2 1) (-2 -1) (-1 -2))
+ ((2 -2) (-2 2))))
+ (#\1 (((-1 -1) (0 -2) (0 2))
+ ((-1 2) (1 2))))
+ (#\2 (((-2 -1) (-1 -2) (1 -2) (2 -1) (-2 2) (2 2))))
+ (#\3 (((-2 -1) (-1 -2) (1 -2) (2 -1) (1 0) (0 0) (1 0) (2 1) (1 2)
+ (-1 2) (-2 1))))
+ (#\4 (((2 1) (-2 1) (1 -2) (1 2))))
+ (#\5 (((2 -2) (-2 -2) (-2 0) (1 0) (2 1) (1 2) (-2 2))))
+ (#\6 (((1 -2) (-1 -2) (-2 -1) (-2 1) (-1 2) (1 2) (2 1) (1 0) (-2 0))))
+ (#\7 (((-2 -2) (2 -2) (2 -1) (0 1) (0 2))))
+ (#\8 (((-1 -2) (1 -2) (2 -1) (1 0) (-1 0) (-2 1) (-1 2) (1 2) (2 1)
+ (1 0) (-1 0) (-2 -1) (-1 -2))))
+ (#\9 (((2 0) (-1 0) (-2 -1) (-1 -2) (1 -2) (2 -1) (2 1) (1 2)
+ (-1 2))))))