Summary

There are different techniques for implementing selectors and loops. Depending on the aim of a piece of code, a certain technique will be more useful than another. This chapter explained the characteristics of different techniques and showed where to use each.

  • Selectors

if..else constructions are very fast for the first few cases and increasingly slower for the rest, with the default case being the slowest. Use if..else constructions for evaluating complex expressions that cannot be reduced to a numbered range for a selector, and either/or situations that are unlikely to be augmented with additional cases in the future.

The switch statement is equally fast for all selectable cases, except for the default case, which is faster than the ...

Get C++ Footprint and Performance Optimization 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.