Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re (tilly) 1: Efficiency and overhead of subs

by tilly (Archbishop)
on Nov 16, 2001 at 19:18 UTC ( [id://125828]=note: print w/replies, xml ) Need Help??


in reply to Efficiency and overhead of subs

If you are into tight code that doesn't waste memory, then Perl is the wrong language for you.

Perl code routinely takes of several times the space and runs at a small fraction of the speed of an equivalent C program. There is nothing you can do about that other than to take up a language whose philosophy on life more closely matches your own. And if you are programming a CGI, the overhead of starting Perl itself is likely to dwarf the puny effects of your modularizing your code (which is unfortunately not free, though it is pretty cheap).

But that said, I strongly recommend that you read the chapter from Code Complete on Optimization. As he says there at length, when it comes to optimization, don't lose the forest for the trees. Concentrate on sane, understandable code. Don't worry about efficiency. And then in the time you save with good development practices, profile and optimize what needs to be optimized.

Unless you are working on simple, fast code which has to work in embedded chips, and admittedly some do, this advice results in a better development balance, and on real projects is ironically likely to wind up with faster code than people who micro-optimize from the start.

So if you have a real programming problem and Perl is a fit, then don't worry about overhead. Program sanely, try not to be stupid, pick decent algorithms, and when you are done, take Devel::DProf out for a spin if need be.

  • Comment on Re (tilly) 1: Efficiency and overhead of subs

Replies are listed 'Best First'.
Re: Re (tilly) 1: Efficiency and overhead of subs
by HamNRye (Monk) on Nov 17, 2001 at 05:46 UTC

    Actually, you might want to spend more time thinking about how your perl will run, not how it's written. If you are writing a CGI, you can use mod_perl on apache, Perl for Isapi on IIS, etc...

    Also, I have found that using Perl2Exe can dramatically speed up a script that gets started often by eliminating the compile time.

    I guess the point is that within reason, programming practice has a lot less to do with efficiency than run time implementation. Welcome to the world of interpreted languages.

    That all said, use references, and avoid large hashes.

    Hammy
    Nothing4sale.org

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (4)
As of 2024-04-24 05:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found