Errr...then don't use perl. Every script you write will load a large, feature-rich interpreter and be recompiled every time - and all modules you use will also be loaded and recompiled on each invocation of your script (unless you use apache mod_perl, that is)

Every integer you store (ok...not every one) will be represented internally as a complex 'scalar' structure which knows all about becoming a string, an object and a reference to other types of data.

Not that perl code can't be fast and efficient, but memory footprint is pretty much always going to suck compared to any non-script language.

Does this matter? Depends what you are doing

Its always good to have fast, efficient code. But its better to have readable, correct code which (in the few places it matters) does clever, less obvious things.

Less negatively, you can pack data compactly in perl using functions like pack and unpack. Function calls do have some overhead as in any language, but you could only notice that in a tight loop. There are various introspection options open to you if your perl was built with -DDEBUGGING and there are useful modules on CPAN in the Devel:: hierarchy for profiling.

But my 2p is that general coding style should be optimised for readability, with the hairy bits confined to areas which measurements have shown to be performance critical (and then only if performance is an issue or you have time on your hands).


In reply to Re: Efficiency and overhead of subs by jbert
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.