You'll find many nodes on the topic of performance optimization. Let me summarize all of them for you: don't optimize unless you need to.

One of the biggest issues programmers face (myself included) is the tendency to say "this won't run fast so I had better speed it up." The reality is, if it runs fast enough, it runs fast enough. Particularly as a system gets large, it becomes more and more difficult to guess what will really speed things up. Even if you speed up a loop 100 times, if the program only spends one percent of its time there you've likely wasted your effort.

But optimizing isn't really bad, is it? I mean, if I optimize everything won't my program will run really fast?

The answer to that is a resounding NO! I can't recall offhand who said it, but one telling quote is "it's easier to optimize correct code than to correct optimized code." Every hoop you jump through to squeeze out every little bit of performance is another chance for your foot to catch on that hoop and make you stumble. You'll likely introduce more bugs and you'll simply waste time trying to second guess whether or not a particular construct can be faster when what you really want to be doing is delivering product. You'll also be more likely to obfuscate your code and make maintenance more difficult. Only when you have a deliverable and you can get an idea how it's likely to be used in a production environment can you really begin to start performance profiling to find out where the bottlenecks, if any, are.

In summary, do not fall into the time-wasting trap of second guessing the performance of your code. Make your code correct and only when you really have a performance problem should you start profiling things. With a performance profile in hand, then you can know where you should be optimizing instead of guessing.

(Note: the above is good general advice and there are definitely times it should be ignored, but once you get to the point where you can make the distinction you'll be giving others this advice :)

Cheers,
Ovid

New address of my CGI Course.


In reply to Re^3: String manipulation by Ovid
in thread String manipulation by hotshot

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.