The Nuts and Bolts

So how do you optimize? Rather than learn a list of specific code optimizations, it’s far more important to understand the correct approach to optimizing. Don’t panic; we will see some programming techniques later, but they must be read in the context of this wider optimization process.

The six steps for speeding up a program are:

  1. Determine that it’s too slow, and prove you do need to optimize.

  2. Identify the slowest code. Target this point.

  3. Test the performance of the optimization target.

  4. Optimize the code.

  5. Test that the optimized code still works (very important).

  6. Test the speed increase, and decide what to do next.

This sounds like a lot of work, but without it you’ll actually waste time and effort and end up with crippled code that ...

Get Code Craft 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.