shithub: femtolisp

ref: 991160b28f27849a616f39059f79cde0b312e01a
dir: /test/bench.lsp/

View raw version
(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)))))