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.


In reply to Re (tilly) 1: Efficiency and overhead of subs by tilly
in thread Efficiency and overhead of subs by stillinger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.