The Computer Language Shootout is a popular if not-so-informative way to compare the speed of various language implementations. Racket does pretty well on their benchmarks, thanks to a lot of effort from various people, especially Eli. They run benchmarks on both 1 core and 4 core machines, so languages with support for parallelism can take advantage in many cases. However, up until this past week, there were no parallel versions of the Racket programs, and therefore Racket didn’t even show up on the 4-core benchmarks. I set out to fix this, in order to advertise Racket’s up-and-coming parallelism constructs.
There are now two new Racket versions of the benchmarks, one each using
mandelbrot benchmark uses futures, getting a speedup of approximately 3.2x on 4 cores, and the
binary-trees benchmark uses places, with a speedup of almost exactly 2x.
I learned a few things writing these programs:
- Racket's parallelism constructs, though new, are quite performant, at least on microbenchmarks. With only two parallel programs, Racket is right now competitive with Erlang on 4 cores.
- Futures are really easy to use; places take a little more getting used to. Both are quite simple once you get the hang of it, especially if you've written concurrent Racket programs before using Racket's threads.
- It can be very surprising which languages are easiest to translate to Racket. F# and OCaml were the easiest, with Scala similar. Programs written in Common Lisp, though fast, were much harder to convert to Racket.
- My quick rule of thumb for whether to choose places or futures: if you program does much allocation in parallel, or it needs to synchronize, then use places. Otherwise, futures are probably easier. I think this is roughly in line with the original design, and there are more applications where synchronization is unnecessary than you would think.
There are a bunch more programs that could have parallel implementations; feel free to hack on them, or to improve mine.