Chapter 7: Performance

His promises were, as he then was, mighty; But his performance, as he is now, nothing.

Shakespeare, King Henry VIII

Long ago, programmers went to great effort to make their programs efficient because computers were slow and expensive. Today, machines are much cheaper and faster, so the need for absolute efficiency is greatly reduced. Is it still worth worrying about performance?

Yes, but only if the problem is important, the program is genuinely too slow, and there is some expectation that it can be made faster while maintaining correctness, robustness, and clarity. A fast program that gets the wrong answer doesn’t save any time.

Thus the first principle of optimization is don’t. Is the program good enough already? Knowing ...

Get The Practice of Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.