Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis cellularmitosis/README.md
Last active Nov 24, 2019

Embed
What would you like to do?
Trivial performance comparison of some Scheme interpreters

Blog 2019/11/2

<- previous | index | next ->

Trivial performance comparison of some Scheme interpreters

Let's use a trivial (recursive) Fibonacci benchmark to compare the performance of a few Scheme interpreters.

(define (fib n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))
(display (fib $n))
(newline)

Specifically, I was interested in looking at start-up time and overall throughput (actually, function-call overhead).

TL;DR

  • 👍 Startup time: Elk, Chicken
  • 👍 Throughput: Chez, Racket

Results

Overall results:

recursive (fib n)

A close-up of the "knee" of the curve:

recursive (fib n) (1)

Start-up time

If we focus on small values of n, we can compare start-up time. Here, non-JIT'ed interpreters will perform well.

Screen Shot 2019-11-02 at 5 51 07 AM

recursive (fib n) (3)

recursive (fib n) (2)

Throughput

If we focus on large values of n, we get a sense of the overall throughput (actually, the function-call overhead) of the interpreters. Here, the JIT'ed interpreters will perform well.

Screen Shot 2019-11-02 at 5 51 32 AM

recursive (fib n) (5)

#!/bin/bash
# brew install guile gambit-scheme chezscheme mit-scheme chibi-scheme chicken racket scheme48 gerbil-scheme kawa
# note: you'll have to hack this script and execute kawa as "kawa -s".
for scheme in elk guile chez mit-scheme csi chibi-scheme scheme48 racket
do
outfile="results-${scheme}.csv"
echo "(fib n),time" > $outfile
# do a dry-run to ensure vfs cache is warm
$scheme >/dev/null 2>&1 <<EOF
(define (fib n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))
(fib 10)
EOF
for n in `seq 1 40`
do
echo "$scheme (fib $n)"
{ time $scheme <<EOF
(define (fib n) (if (< n 2) n (+ (fib (- n 1)) (fib (- n 2)))))
(display (fib $n))
(newline)
EOF
} 2>&1 | grep real | awk '{print $2}' | sed 's/^0m//' | sed 's/s$//' | sed "s/^/$n,/" >> $outfile
done
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.