Caching

Caching is often associated with data and instruction caching on modern processors. But, caching opportunities appear in much wider contexts, including application-level coding and design. Caching is about remembering the results of frequent and costly computations, so that you will not have to perform those computations over and over again.

Caching opportunities are easier to detect and implement in the coding arena. Evaluating constant expressions inside a loop is a well known performance inefficiency. For example:

for(... ;!done;... ) {
   done = patternMatch(pat1, pat2, isCaseSensitive());
   }

The patternMatch() function takes two string patterns to match and a third argument indicating whether a case-sensitive match is required. The ...

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.