What is Premature Optimization?

A

Arved Sandstrom

tenxian said:
Is it good or bad?

Not good...the keyword being "premature", meaning "untimely, too soon,
hasty" in this context.

Premature optimization often refers to steps taken to improve speed or
reduce memory consumption, *before* there is reason to believe that such
steps are necessary. It does _not_ refer to judicious choice of fast and/or
memory-consumption-reducing architecture, design, algorithms and data
structures at the earliest possible stage.

AHS
 
J

Joshua Cranmer

tenxian said:
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...
 
T

thufir

Not good...the keyword being "premature", meaning "untimely, too soon,
hasty" in this context.

Premature optimization often refers to steps taken to improve speed or
reduce memory consumption, *before* there is reason to believe that such
steps are necessary. It does _not_ refer to judicious choice of fast
and/or memory-consumption-reducing architecture, design, algorithms and
data structures at the earliest possible stage.

Donald Knuth said, paraphrasing Hoare[1],

* "We should forget about small efficiencies, say about 97% of the
time: premature optimization is the root of all evil." (Knuth, Donald.
Structured Programming with go to Statements, ACM Journal Computing
Surveys, Vol 6, No. 4, Dec. 1974. p.268.)

http://en.wikipedia.org/wiki/Optimization_(computer_science)

Actually, he's talking about *small* efficiencies. Just thought I'd post
the quote!


-Thufir
 
A

Arne Vajhøj

thufir said:
Donald Knuth said, paraphrasing Hoare[1],

* "We should forget about small efficiencies, say about 97% of the
time: premature optimization is the root of all evil." (Knuth, Donald.
Structured Programming with go to Statements, ACM Journal Computing
Surveys, Vol 6, No. 4, Dec. 1974. p.268.)

http://en.wikipedia.org/wiki/Optimization_(computer_science)

Actually, he's talking about *small* efficiencies. Just thought I'd post
the quote!

That is what it is all about.

Programmers taking 4 nice reachable lines of code that work
and replace them with 40 unreadable lines with 3 bugs to achieve
a 5% speed increase of that code which because that code only
takes 0.1% of total time result in a total performance improvement
of 0.0005% and cost the company tens of thousands of dollars to
find and fix the bugs !

Arne
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top