This is a straightforward implementation of the Game of Life rules in 10 programming languages:
- C++ (version 2011 and later) — life.cc
- Python (version 2 and 3) — life.py, life.py3
- PHP — life.php
- Perl (version 5) — life.pl
- Ruby — life.rb
- JavaScript/ECMAScript (Node.js) — life.js
- Tcl — life.tcl
- Lua — life.lua
- Scheme (at least R5RS and later) — life.scm
- and my own programming language called MANOOL — life.mnl
The program simply displays an initial configuration and then the configuration after G generations and exits. The grid (board) dimensions are given by parameters N and M and the initial configuration is hard-coded but can be modified at your will. The universe is wrapped.
The MANOOL version has an additional parameter, AllocOpt, which determines whether the code is explicitly memory allocation-aware or completely relies on copy-on-write aspects of the language semantics.
The main purpose of this repository is to have a benchmark (which is both computationally-intensive and fun) to compare performance of the MANOOL translator with that of other language implementations and to compare MANOOL with other languages. However, while coding the same task in so many of them, I suddenly realized how bizarre are the similarities (and differences) between programming languages.
The choice of languages is made due to the following:
- These are all dynamically-typed programming languages (except C++, which is included for reference purposes)
- The implementations have relatively lightweight installation packages for Unix-like systems (again, except for C++ ;-)
A performance comparison report and an analisis of MANOOL syntax and semantics with respect of these programming languages is to follow at some point of the future.
The examples are written in the most idiomatic but most similar way from the performance comparison and stylistic point of view. I did not have any previous working experience with Python, Ruby, Tcl, Lua, and Scheme (had never written code of similar complexity), so you are welcome to suggest improvements if there are even more idiomatic ways to use them.
Examples of command line to run:
g++ -std=c++11 -O3 life.cc && time ./a.out; rm -f a.out
or
clang++ -std=c++11 -O3 life.cc && time ./a.out; rm -f a.out
time python life.py
or
time python3 life.py3
time php life.php
time perl life.pl
time ruby life.rb
time node life.js
time tclsh life.tcl
time lua life.lua
or
time luajit life.lua
time guile life.scm
or
csc -C -O3 life.scm && time ./life; rm -f life
time MNL_PATH=~/manool/build/lib ~/manool/build/mnlexec life.mnl
To clone this repo:
git clone https://github.com/rusini/life10.git
Have fun! — rusini — [email protected]