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?? |
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:
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
In Section
Seekers of Perl Wisdom
|
|