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 (via 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++ ;-).
For a performance comparison report, refer to Benchmarks.md. The graph is in Benchmarks.png:
An analysis of MANOOL syntax and semantics with respect to these programming languages is to follow at some point in 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.
Construction of the implementation in MANOOL is discussed in detail in the Reddit post “A primer on the programming language MANOOL: Conway's Game of Life”.
Examples of command line to run:
-
C++:
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
-
Python:
time python life.py
or
time python3 life.py3
-
PHP:
time php life.php
-
Perl:
time perl life.pl
-
Ruby:
time ruby life.rb
-
JavaScript/ECMAScript:
time node life.js
-
Tcl:
time tclsh life.tcl
-
Lua:
time lua life.lua
or
time luajit life.lua
-
Scheme:
time guile life.scm
or
csc -C -O3 life.scm && time ./life; rm -f life
-
MANOOL:
time MNL_PATH=~/manool/build/lib ~/manool/build/mnlexec life.mnl
To clone this repo:
git clone https://github.com/rusini/life10
Have fun! — rusini — info@manool.org