Thursday, August 11, 2011

How To Optimize

Donald Knuth:


We should forget about small efficiencies, say about 97% of the
time: premature optimization is the root of all evil. Yet we
should not pass up our opportunities in that critical 3%.


(Source is here. See the 2nd paragraph on the right column on page 8.)

Here's the general advice on optimizing:

1. Don't do it
2. Don't do it yet
3. Don't do it until someone complains that it is slow.
4. And when someone complains, find the bottleneck - measure it! Get a feel of how slow it is. Remember:

Don't optimize what you cannot measure because therein lies the road to insanity.

5. Optimize one step at a time and always, always measure the gain. If there's no gain then undo your "optimization".

0 Comments:

Post a Comment

<< Home