Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: Code Efficiency: Trial and Error?

by trs80 (Priest)
on Oct 12, 2002 at 16:04 UTC ( #204774=note: print w/replies, xml ) Need Help??


in reply to Code Efficiency: Trial and Error?

Q1) how do other Monks go about optimizing their code?
Q2) when faced with more than one obvious way to do something, what's the determining factor?
Q3) surely this has to be more than "trial and error" ..? *grin*

A1) Since reading between the lines it seems you are working with a database most of the time, there is much more to getting efficient code then just the Perl part of it. You need to be concerned with the network (if it is a remote database), the indexing of the tables, this can make a big difference on the speed of your code. In one recent project I got a ten fold difference in speed on a report by adding the appropriate indexes to the tables. As far as Perl efficiency is concerned this also very dependent on the type of data you are dealing with. I recommend you use a profiler to find out where the most time is being spent in you code. You might want to checkout Devel::AutoProfiler .

A2) For me unless there is a known efficiency issue I code to my level as much as possible. I occasionally will use code outside of my comfort zone in the hopes of adding it at some point to my bag of tricks, but some code just doesn't "sound" right and makes more of a maintenance issue then anything else. Another thing to consider is Lifespan of the code in question. If this is a one time or seldom run piece of code you most likely won't recover from the time "wasted" in making more efficient. Optimize only when it is beneficial in the grand scheme of things.

A3) Using different benchmarking tools and code profiling you can determine what is causing the bottleneck and code those sections differently.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (4)
As of 2020-07-14 23:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?