shithub: femtolisp

Download patch

ref: fff86746c7d0a817d504a54a0db417107a44fe85
parent: 2282a527e0baad565075bdeb574b5b0b69f6f1d4
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Wed Dec 18 21:14:30 EST 2024

add bench.lsp

--- a/meson.build
+++ b/meson.build
@@ -218,7 +218,8 @@
 tests_dir = join_paths(meson.current_source_dir(), 'test')
 
 test('argv.lsp', flisp, args: ['argv.lsp'], workdir: tests_dir)
-test('hash.lsp', flisp, args: ['hashtest.lsp'], workdir: tests_dir)
+test('bench.lsp', flisp, args: ['bench.lsp'], workdir: tests_dir)
+test('hashtest.lsp', flisp, args: ['hashtest.lsp'], workdir: tests_dir)
 test('mp.lsp', flisp, args: ['mp.lsp'], workdir: tests_dir)
 test('perf.lsp', flisp, args: ['perf.lsp'], workdir: tests_dir, timeout: -1)
 test('tme.lsp', flisp, args: ['tme.lsp'], workdir: tests_dir)
--- /dev/null
+++ b/test/bench.lsp
@@ -1,0 +1,36 @@
+(load "test.lsp")
+
+;; each benchmark is repeated N times to accomodate
+;; for the performance increase of current systems
+(define N 100)
+
+;; "Performance and Evaluation of Lisp Systems" (1985), Richard P. Gabriel
+(princ "tak:  ")
+(define (tak x y z)
+  (if (not (< y x))
+      z
+      (tak (tak (- x 1) y z)
+           (tak (- y 1) z x)
+           (tak (- z 1) x y))))
+(time (dotimes (n N) (assert (equal? 7 (tak 18 12 6)))))
+
+;; same as tak, but:
+;;   (not (<    →   (>=
+;;   (- ... 1   →   (1-
+;; this will show how extra calls (no inlining) make things slow
+(princ "tak_: ")
+(define (tak_ x y z)
+  (if (>= y x)
+      z
+      (tak_ (tak_ (1- x) y z)
+            (tak_ (1- y) z x)
+            (tak_ (1- z) x y))))
+(time (dotimes (n N) (assert (equal? 7 (tak_ 18 12 6)))))
+
+;; q2 - http://lispology.com/show?314T
+(princ "q2:   ")
+(define (q2 x y)
+  (if (or (< x 1) (< y 1)) 1
+    (+ (q2 (- x (q2 (- x 1) y)) y)
+       (q2 x (- y (q2 x (- y 1)))))))
+(time (dotimes (n N) (assert (equal? 31 (q2 7 8)))))
--- a/test/mkfile
+++ b/test/mkfile
@@ -1,3 +1,3 @@
 test:QV:
-	for(t in unittest.lsp argv.lsp hashtest.lsp torus.lsp tme.lsp mp.lsp perf.lsp torture.scm)
+	for(t in unittest.lsp argv.lsp bench.lsp hashtest.lsp torus.lsp tme.lsp mp.lsp perf.lsp torture.scm)
 		../$O.out $t