Key Points

Coding optimizations are local in scope and do not necessitate understanding of overall program design. This is a good place to start when you join an ongoing project whose design you don't yet understand.

The fastest code is the one that's never executed. Try the following to bail out of a costly computation:

  • Are you ever going to use the result? It sounds silly, but it happens. At times we perform computation and never use the results.

  • Do you need the results now? Defer a computation to the point where it is actually needed. Premature computations may never be used on some execution flows.

  • Do you know the result already? We have seen costly computations performed even though their results were available two lines above. If you already ...

Get Efficient C++ Performance Programming Techniques 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.