Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Optimizing existing Perl code (in practise)

by sauoq (Abbot)
on Aug 18, 2002 at 22:50 UTC ( [id://191032]=note: print w/replies, xml ) Need Help??


in reply to Optimizing existing Perl code (in practise)

The real trick isn't optimizing your code but optimizing your solution. Maybe you can write the same code three different ways but if that code implements an O(N2) algorithm when there is an O(N) algorithm that will do it doesn't matter much whether you shave a few microseconds off each iteration.

Successfully choosing the right algorithm takes careful consideration of the problem. If there is a secret to it at all it's probably choosing the right representation for your data. How to do that is a matter of experience and education. There isn't a cookbook solution to it because it usually depends greatly upon details of the problem you need to solve.

-sauoq
"My two cents aren't worth a dime.";
  • Comment on Re: Optimizing existing Perl code (in practise)

Replies are listed 'Best First'.
Re: Re: Optimizing existing Perl code (in practise)
by Xanatax (Scribe) on Aug 20, 2002 at 10:56 UTC
    The real trick isn't optimizing your code but optimizing your solution.

    this is a good paraphrase of my answer... hell yeah, i optimize my code... but it's the data bottlenecks i optimize, not the millisecond differences you'd only get by porting to C. when all i get is milliseconds, i purely write for readability/security/correctness, not speed.

    i try to understand what my database does to retrieve/store data, so the requests i make of it can use indices, not full searches. i try to dump the results of a query into a perl hash if i reuse it, to avoid requerying. i try to keep the data ordered in such a way as to avoid the actual data structure causing problems, etc.

    i find that for what i want to do one or both of {perl, mysql} always has the data structure i want (in terms of efficiency of search, add, delete), so i can almost always avoid doing the hard work.. that makes for efficiency of development on several levels. by knowing perl/mysql i have an easy answer to all my data structure problems, i just have to use the struct, not build one first. and it is readable by others simply by virtue of being standardized (ie SQL 92)

    second, if there is an error in the data structure, the easy to fix ones are my fault (i used the struct wrong), and the hard ones are someone elses. if i'm using say, some feature new to mysql 4.0.0alpha and it breaks, we just add it to the bug list and wait for 4.0.1 -- the fix is free, i or my employer don't have to pay for me to debug, rewrite, debug, etc...

    if i were the guy writting mysql it would be a different story, but it's not like they write it in perl either...

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (2)
As of 2024-04-20 04:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found