Re: What is Premature Optimization?



tenxian wrote:
Is it good or bad?

(Typically it's considered bad form to put the main question as the subject.)

Anyways, "premature optimization" (most likely deriving from the old quote, "Premature optimization is the root of all evil," attributed to Donald Knuth, author of TAOCP) is a simple phrase that is not idiomatic, and thus can be parsed directly.

Premature - something happening before it should
Optimization - the process (or at least an attempt) of increasing efficiency (with general connotation to time and somewhat so less so to space)

Therefore, "premature optimization" is the process whereby the efficiency is increased before it should be, or, cleaning up a bit, "optimizing" code before one can say whether or not it should be. It generally refers to people optimizing code based on where he or she believes the code to be underperforming, instead of based on rigorous tests which pinpoint the exact blocks which are consuming the most time.

As to your latter question, it is generally considered poor form. Knuth's quote I've cited above, but another programmer (his name escapes me at the moment) said something to the effect that "more sins are committed in the name of optimization than any other cause--including stupidity." I suspect it is up to decide to yourself, though...

--
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald E. Knuth
.



Relevant Pages

  • RE: frozenset question
    ... but it costs you two seconds to type the comment in ... > the code explaining why you used frozenset instead of the more ... > THAT is the lesson of premature optimization: ...
    (comp.lang.python)
  • Re: gets
    ... foo = tmp2 ... > the latter because of efficiency is a case of premature optimization. ...
    (comp.lang.ruby)
  • Re: how big can an array be before it becomes unmanageable?
    ... >IMHO, you should normally *not* do that kind of optimization, since it ... >is a premature optimization. ... is faster is some sort of impure thought, ... If you can make code fast by algorithm choice or simplicity or by ...
    (comp.lang.java.programmer)
  • Re: Help me understand why the Ruby block is slower than wit
    ... I work on video games. ... A good portion of our job is optimization. ... If we didn't do *some* premature optimization, ...
    (comp.lang.ruby)
  • Re: AMD64 optimization on FreeBSD 5.4 i386
    ... > On 04 Apr Bachelier Vincent wrote: ... To quote the Handbook: ... ``The optimization -O2 is much slower, ...
    (freebsd-questions)