Another key is 'micro-' (or 'nano-', which I started using because some tiny optimizations in Perl made what I was used to calling 'micro-optimization' seem huge in comparison because Perl can have much bigger overhead than something like C).

I wouldn't much mind many discussions of optimization that are premature if they covered real optimization techniques. Instead, most premature optimization discussions end up dealing with really tiny tasks.

This is problematic because, 1) being tiny, they are usually a part (tiny part) of a wide variety of algorithms so people overestimate their importance ("I can apply this speed-up all over the place!"). And 2) being tiny, the difference between what Benchmark.pm measures and what you can actually gain from using them is huge so people focus on "four times as fast!" and don't even think about "adds up to less than 1% of the run time of my script".

So, premature optimization is a bad habit but can be fun and educational in a perverse sort of way. And in very rare situations, micro-optimizations can actually pay off (at least a little bit). So I can cut people slack for playing with premature optimization as a learning exercise if it isn't micro-optimization. And I can see attempting micro-optimization if you've done the profiling to show that this micro-operation is actually adding up to a significant portion of your run time (that is, if the optimization isn't premature).

But I will always find premature micro-optimization to be something to be critical of when I see it (especially if I don't see anyone else pointing out that the numbers aren't nearly as exciting as they appear and the techniques aren't automatically the best choice in real code).

In that other thread, we see examples of both: people suggesting that the fastest code should be used in future code and people thinking that a 4x speed-up in a micro-optimization could end up with a 4x speed-up of total run time.

So, in theory, premature nano-optimization could be educational. In practice, I don't usually see interesting discoveries made and I very often see enthusiastic adoption of 'the winner' to the point of any other method being 'corrected' because it isn't 'efficient'.

- tye        


In reply to Re^2: Golfing and Sprinting (micro) by tye
in thread Golfing and Sprinting by kvale

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.