Initial import
authorMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 9 Sep 2015 23:10:58 +0000 (23:10 +0000)
committerMatthew Mondor <mmondor@pulsar-zone.net>
Wed, 9 Sep 2015 23:10:58 +0000 (23:10 +0000)
mmsoftware/cl/test/fib.lisp [new file with mode: 0644]
mmsoftware/cl/test/simple-vector-characters.lisp [new file with mode: 0644]

diff --git a/mmsoftware/cl/test/fib.lisp b/mmsoftware/cl/test/fib.lisp
new file mode 100644 (file)
index 0000000..16da3e4
--- /dev/null
@@ -0,0 +1,45 @@
+
+(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
+
+|#
diff --git a/mmsoftware/cl/test/simple-vector-characters.lisp b/mmsoftware/cl/test/simple-vector-characters.lisp
new file mode 100644 (file)
index 0000000..3db861a
--- /dev/null
@@ -0,0 +1,60 @@
+
+(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))))))