Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

(jeffa) Re: Optimizing existing Perl code (in practise)

by jeffa (Chancellor)
on Aug 18, 2002 at 22:21 UTC ( #191030=note: print w/ replies, xml ) Need Help??


in reply to Optimizing existing Perl code (in practise)

If it has been said once it has been said a thousand times "beware of premature optimization!" Ask yourself, "does this really need to be faster? Really?"

I think a very important item to optimize is code maintainabibilty - how easy is it to extend your program and fix bugs that break your code?

So, how do i optimize my Perl code? I generally don't (but i do try to get it right the first time - measure twice, cut once). If i do, it is to replace areas of wheel re-invention with CPAN modules, or to refactor items into classes to improve robustness. If i wanted faster code i would port it to C instead, but since most of what i write relies on database and web servers, Perl is 90% of the time not the bottleneck.

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)


Comment on (jeffa) Re: Optimizing existing Perl code (in practise)
Re: (jeffa) Re: Optimizing existing Perl code (in practise)
by cybear (Monk) on Aug 19, 2002 at 10:56 UTC
    The fastest script in the world is worthless if a change in your
    system's directory structure breaks your code and you can't fix it.

    If you bother to optimize for anything, do it for maintainability
    But never forget "monitorability".

    Unless your script is being called to do huge jobs, or your resources
    are very restricted (Sparc Ultra 1 or Intel 486, etc.) optimization for
    speed is not usually that big an issue.

    However, thorough and correct logging of events, meaningful commentary
    in the script itself, reusability of the code; these will all help
    with maintainability.

      Another, and I think far more common case, where optimization for speed is rightfully desirable would be the code that drives a dynamic website. See perrin's impressive eToys success story for an admittedly extreme example; when you're facing a million pageviews an hour, you don't want your code to be wasting time, but even much lesser loads make speed an important goal. Nevertheless, of course, it does not override the factor of maintainability.

      Makeshifts last the longest.

        I agree. But wouldn't you concider that a "huge job"? - cybear

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (10)
As of 2014-12-17 19:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (31 votes), past polls