Lets assume you have a program that takes one hour to run:

somefunction() # takes 1 second to run foreach ( @bigmightarrayof360000 ) { someotherfunction($_); #takes 0,01 seconds to run }

Now if you could throw away some error checking code in somefunction() to have its runtime down to 0,5 seconds, would you do it? Your program would gain an unnoticable speedup and in case of error either silently fail or even produce inconsistent data

There are a few golden rules in optimization:

* Don't optimize when you don't need to, i.e. if the program runs fast enough, don't optimize

* Don't optimize prematurely

* Don't optimize where it doesn't count. Usually say 5% of the code is responsible for 95% of the runtime. If you optimize in the other 95% of the code, you wasted your time for minimal gain

* Optimization is a trade off. You might gain speed, but most of the time you lose on readability, memory usage, maintainability or safety. So be sure you can afford the loss.

You might also like to read the section 'When to optimize' in Optimization_(computer_science)


In reply to Re: file test operations by jethro
in thread file test operations by neutron

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.