Skip to content

Instantly share code, notes, and snippets.

@cellularmitosis

cellularmitosis/README.md

Last active Dec 30, 2020
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
@cellularmitosis

This comment has been minimized.

Copy link
Owner Author

@cellularmitosis cellularmitosis commented May 18, 2020

@mgubi

This comment has been minimized.

Copy link

@mgubi mgubi commented Dec 30, 2020

Why not add also Guile 1.8? As far as I know the interpreter there performs better than in the Guile 2 series. Only Guile 3 seems to be finally on par with that. Also s7 scheme ( https://ccrma.stanford.edu/software/snd/snd/s7.html ) is a popular choice for embedding and the author claims is quite fast. It would be interesting to compare these to chibi, for example.

@mgubi

This comment has been minimized.

Copy link

@mgubi mgubi commented Dec 30, 2020

Update: Just out of curiosity I've tried (fib 40) on my machine (MacBook Air 2019) for Guile 1.8, Guile 2.2.7, Guile 3.0.4 and S7, this are the results:
Guile 1.8.8 : 40.595 sec
Guile 2.2.7 : 8.102 sec
Guile 3.0.4 : 3.864 sec
S7 : 3.297 sec
The results for Guile2/3 are from the compiled code (excluding the compilation time). If we force Guile2/3 to use only the interpreter (with GUILE_AUTO_COMPILE=0 and clean cache) we have
Guile 2.2.7: 120 sec
Guile 3.0.4: 60 sec

@cellularmitosis

This comment has been minimized.

Copy link
Owner Author

@cellularmitosis cellularmitosis commented Dec 30, 2020

@mgubi interesting, thanks for contributing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment