Benchmark of naive R5RS keyword implementation Lassi Kortela 17 Oct 2019 11:02 UTC

Here's a half-joking, half-serious benchmark of the portable
syntax-rules implementation with no native keyword support:


(import (chezscheme) (srfi :177))

(define fib
   (lambda (n)
     (if (<= n 2) 1 (+ (fib (- n 2))
                       (fib (- n 1))))))

(define key-fib
   (keyword-lambda ((n))
     (if (<= n 2) 1 (+ (keyword-call key-fib (n (- n 2)))
                       (keyword-call key-fib (n (- n 1)))))))

(time (fib 40))
(time (keyword-call key-fib (n 40)))


$ chez --libdirs .. --program bench-r6rs.sps
(time (fib 40))
     no collections
     0.857526649s elapsed cpu time
     0.866265000s elapsed real time
     0 bytes allocated
(time (keyword-call key-fib ...))
     1163 collections
     2.456871349s elapsed cpu time, including 0.034346931s collecting
     2.489591000s elapsed real time, including 0.040236000s collecting
     9824823472 bytes allocated, including 9825662288 bytes reclaimed

The keyword version is about 3 times as slow as the non-keyword version.
I think it's not too bad, considering this is about the craziest
possible example (dumbest way to do fibonacci, with dumbest way to pass
arguments :)