"Premature optimization is the root of all evil" - Donald Knuth

You shouldn't go through contortions to make your program run a bit faster if it's not needed in the first place. It's just wasted effort, and will make your program harder to read and maintain.

I'm not saying you should never optimize, if a part of a program really *is* running significantly slowly, then by all means it should be sped up. But if you don't even check if it's needed, you could be wasting time optimizing, and making it more obfuscated in the process.

For example, check out these two ways to swap two variables: (Actually they're not exactly the same, for the first one to work they must be integers or same-length strings)

$x ^= $y ^= $x ^= $y; ($x, $y) = ($y, $x);
The first one is a bit faster, but if I didn't just say what it did (or if you had already seen it before) it would probably take a while to figure it out. The second one, it's obvious (if you know Perl) what it's doing, and unless it's going to be called 1000s of times it won't make any noticible speed difference.

--MrNobo1024
s]]HrLfbfe|EbBibmv]e|s}w}ciZx^RYhL}e^print


In reply to Re: Faster Perl, Good and Bad News by MrNobo1024
in thread Faster Perl, Good and Bad News by abitkin

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.