This repository uses different languages to demonstrate Conway’s Game of Life.
All the program accepts 2 arguments: size of board and number of initial random cells.
They will run for 100,000 rounds and exit.
It is created for 2 purposes:
- Provide a hello-word example.
- Provide a minimal benchmark.
Each directory under root (this one) contains code written in one specific language.
I ran it with 40 board size and 800 initial seeds. C int array version is treated as the benchmark.
Version | Time(s) | Environment |
---|---|---|
C (int array) | 1.08 | gcc 10.2.0 |
C++ (STL) | 1.6 | gcc 10.2.0 |
C++ (array) | 1.539 | gcc 10.2.0 |
Rust | 1.58 | cargo 1.47.0 |
OCaml | 3.8 | ocamlc 4.10.0, dune 2.6.1 |
Julia | 7.2 | Julia 1.5.2 |
Common Lisp | 10.8 | SBCL 1.4 |
Scala | 31.5 | Scala 3.1.2, JVM 11.0.14 |
Elixir (array) | 312 | Elixir 1.11.3/Erlang OTP 23 |
Elixir (map) | 281 | Elixir 1.11.3/Erlang OTP 23 |
Elixir (set) | 236 | Elixir 1.11.3/Erlang OTP 23 |
Elixir (ets) | 225 | Elixir 1.11.3/Erlang OTP 23 |
I would say OCaml is very impressive here. It is really a sweet point between development speed and runtime performance.
Also it is not fair for Elixir. The program is computing centric and the algorithm is not optimized for concurrency. In a IO bound scenario, I believe Elixir would have better performance.