Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re^2: What's Perl good at or better than Python (Game of Life, Rosetta and Performance References)

by eyepopslikeamosquito (Archbishop)
on Oct 16, 2021 at 22:24 UTC ( [id://11137640]=note: print w/replies, xml ) Need Help??


in reply to Re: What's Perl good at or better than Python.
in thread What's Perl good at or better than Python.

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 Added Later

Game of Life References Added Later

Rosetta Code (Many Different Languages)

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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137640]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (7)
As of 2024-03-29 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found