Optimizing C++/Writing efficient code

From Wikibooks, open books for an open world
Jump to: navigation, search

In this chapter, guidelines are presented for the avoidance of inefficient operations and for the preparation of source code for a possible optimization stage - all without jeopardizing code safety or maintainability.

Following these guidelines might result in no overall performance gain. But equally there is unlikely to be a performance loss. The guidelines can therefore be applied without worrying about their impact on performance. It is advisable always to follow these guidelines, even in code portions that have no particular efficiency requirements.

  1. Performance improving features
  2. Performance worsening features
  3. Constructions and destructions
  4. Allocations and deallocations
  5. Memory access
  6. Thread usage