Skip to content
Some code to test the performance of the implementation of STM in Clojure
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.


This is just a quick hack. I tried to come up with more sophisticated functions which would drive the STM machine into the various corners available. However, those functions I could come up with, which would do this in a repeatable, reliable way, would all use (Thread/sleep x) which lead to the benchmarks depending mainly on those sleep times.

How to run

Note, that the projects calls Clojure 1.2.1 as its dependency. Usually I will use a Clojure compiled from the sources and run its very basic REPL with

java -cp path/to/my/compiled/clojure.jar:. clojure.main

from the top of this project. If you want to use a parallel garbage collector, you may want to try

java -cp path/to/my/compiled/clojure.jar:. -XX:+UseParallelGC clojure.main

However, on my machines a parallel GC gave only about 2% speedup.

Then I ususally paste the functions from this project and look how they perform. Only the development of the functions is done with swank and slime.

To load the complete benchmark suite you can issue

(load-file "src/clj_stm_perf_test/core.clj")

If you want to run (almost) all function, use


Oh my god, it’s full of constants

Yes, there is actually lots of seemingly magic numbers in there. All these were chosen so that the benchmark runs well on the machines that i have access to. Most importantly there were no visible improvements from HotSpot to spot anymore.

Further Reading

Everyone loves to cite Mark Volkmans still valid article at however, I think we should add a recent Master’s Thesis by Peder R. L. Nielsen and Patrick T. Kristiansen to the list of important resources for details on Clojure’s STM:

These guys did an awesome job.


Copyright (C) 2011 Stefan Kamphausen

Distributed under the Eclipse Public License, the same as Clojure. See file COPYING.

Something went wrong with that request. Please try again.