Clojerl Ant Simulation
This is a comparison of running Rich Hickey’s Clojure Ant Simulation (2009) on both the JVM and the BEAM virtual machines. The original Clojure source written in 2008 has been ported to Clojerl line by line with only two differences:
- Clojure holds the ants state in agents and the cells of the board are wrapped in ref. Clojerl uses processes and message passing with per-process serialization of updates and without transactions
- Clojure JVM version uses Java Swing for the graphics, Clojerl uses wxwidgets
The code is compiled with the Clojerl compiler to the BEAM Virtual Machine. Note that you must run with the -m
switch:
git clone https://github.com/clojerl/clojerl.git
cd clojerl
make
wget ...ants.clje
bin/clojerl -m ants
The results are very comparable! Clojerl version uses a lot less memory (with default JVM settings for both). Thank you to Juan Facorro the author of Clojerl for contributing some improvements to the state handling and painting and for writing Clojerl!
Here are some statistics of running the Clojure and the Clojerl programs over a five hour soak test:
Clojure | Clojerl | |
---|---|---|
VM | JVM | BEAM |
Real Memory GB | 1.69 | 0.175 |
Virtual Memory GB | 9.9 | 5.4 |
Threads | 83 | 28 |
% CPU | 163% | 115% |
CPU Time | 4:02:23 | 5:00:10 |
Test run simultaneously on a Late 2012 Mac Mini, 2.5 GHz Intel Core i5 with 16GB RAM, OTP 22 and Clojure 1.8 running on Hotspot 1.80_45-b14.
Compare the original Clojure/JVM Ants Simulation source vs the Clojure/BEAM Ants Simulation source below:
The simulator was announced on March 20th 2008 as part of the Clojure Concurrency Talk.