Don't Just Do Something, Stand There!
The most powerful optimization technique in any programmer's
toolbox is to do nothing.
This very Zen advice is true for several reasons. One is the
exponential effect of Moore's Law — the smartest, cheapest, and
often
fastest
way to collect performance gains is
to wait a few months for your target hardware to become more capable.
Given the cost ratio between hardware and programmer time, there are
almost always better things to do with your time than to optimize a
working system.
We can get mathematically specific about this. It is almost
never worth doing optimizations that reduce resource use by merely a
constant factor; it's smarter to concentrate effort on cases in which
you can reduce average-case running time or space use from
O(
n
2) to
O(
n
) or O(
n
log
n
),[112] or similarly reduce from a higher
order. Linear performance gains tend to be rapidly swamped by Moore's
Law.[113]
Another very constructive form of doing nothing is to not write
code. The program can't be slowed down by code that isn't there. It
can be slowed down by code that
is
there but
less efficient than it could be — but that's a different
matter.