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

Rosetta Code (Many Different Languages)

Extra:

References on Comparing Programming Languages Added Later

See Also

Many references were added long after the original reply was made


In reply to Re^2: What's Perl good at or better than Python (Game of Life, LLiL, Rosetta and Performance References) by eyepopslikeamosquito
in thread What's Perl good at or better than Python. by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.