There are times when we want to understand and optimize performance of Perl programs, and there are other times when we just want a program to run faster, fast. Having a computation-intensive task at hand (hint: nested loops, numbers, arithmetics) speaks for a brute force approach - simply rewriting the algorithm in C is likely to yield great benefits with little intellectual strain.
Here's a little case study: a Perl version of a program which performs some 360,000,000 arithmetic operations takes 135 wallclock seconds to execute. After moving the computation to C the execution time drops to 1.7 seconds - a speedup of more than 70. Hint: to keep life simple given such a case, don't even bother with perlxs or worry about efficient I/O... just port your code to C, invoke the C program via system() and communicate through files or stdin/stdout.
(Of course, the same insight certainly applies to any interpreted language, not just Perl.)
No comments:
Post a Comment