Multiple implementations of Conway's game of life in Perl and C
with a focus on performance. Really? Any chance of seeing your source code?
A few years back I became a bit obsessed with implementing Game of Life in both Perl and C++, as described in detail at:
The benchmark timings above were for running the famous Lidka
Methuselah for 30,000 generations.
The code that produced the fastest benchmark times can be found here:
Summary: The C++ version of the simple GoL algorithm was 450/36 = 12.5 times faster than the Perl version; memory use was 2.8 less, 517,340K v 1,455,004K. For the complex GoL algorithm, C++ was 17/0.08 = 212.5 times faster; memory use was 10.1 times less, 69,632K v 700,000K.
The code that produced the fastest early benchmark times for Rosetta Code: Long List is Long can be found here:
... though these early benchmarks were later smashed by a month-long marioroy rampage. :)
TODO (maybe): Benchmark Perl vs C++ for Rosetta PGA-TRAM and Rosetta Code: Long List is Long (and write a performance meditation with the results of GoL, PGA-TRAM, Long-List-is-Long). PGA-TRAM Benchmark done: Risque Romantic Rosetta Roman Race
Update
Instructively, tweaking the Perl code, via a long series of micro-optimizations,
reduced the running time from 1635 secs to 450 secs (3.6 times faster),
while finding a better algorithm reduced it from 450 secs to 17 secs (26.5 times faster).
Similar numbers for the C++ code confirm
the old Kernighan and Plauger adage:
"Don't diddle code to make it faster -- find a better algorithm".
Further Update
> My C implementation of Life had a much larger memory footprint (no readily-available hash implementation)
This is very surprising! I suspect your implementation of hashes in C was sub-optimal. :)
In my GOL code, the C++ version consistently had a much lower memory footprint than the Perl version.
As detailed here the memory footprint of the fastest versions when hit with a nasty three million cell test case:
69,632K for my C++ version, 700,000K for my Perl version,
and 18,138,504K (i.e. 18 GB!) for CPAN Game::Life::Infinite::Board.
Performance References
Game of Life References
Long List is Long References
- Re: Rosetta Code: Long List is Long - JudySL code by marioroy (2023) - JudySL array implementation
- Solving the Long List is Long challenge, finally? by marioroy (2023) - Perl versions in replies use Sort::Packed, Tie::Hash::DBD, DB_File, IPC::MMA, Crypt::xxHash, Tokyo Cabinet, Kyoto Cabinet, Tkrzw sharding, Tkrzw llil4tkh, Tkrzw llil4tkh2
- [OT] The Long List is Long resurrected by marioroy (2024) (mentions Taichi Lang, a DSL embedded in Python)
Rosetta Code (Many Different Languages)
- Tales from writing a RPN evaluator in Perl 5, Perl 6 and Haskell
- Five Ways to Reverse a String of Words (C#, Perl 5, Perl 6, Ruby, Haskell)
- Yet Another Rosetta Code Problem (Perl, Ruby, Python, Haskell, ...)
- Rosetta PGA-TRAM
- Rosetta code: Split an array into chunks
- Re^2: Perlplexation - foreach shoulda Known (Rosetta: Perl, Python, Ruby)
- Rosetta Dispatch Table (Interview Question)
Extra:
References on Comparing Programming Languages Added Later
See Also
- DBM (computing) - DBM Computing (wikipedia)
- Tkrzw: a set of implementations of DBM - Tkrzw is a C++ library implementing DBM with various algorithms. It features high degrees of performance, concurrency, scalability and durability (requires C++17 on Windows or Unix)
Many references were added long after the original reply was made
| [reply] |