6.2. Avoid Unnecessary Memory Accesses

Generally speaking, huge performance improvements come from algorithm changes.

Use an ordinary execution profiler (such as gprof or callgrind) to find hot-spots in the code. That will estimate the amount of time spent in each part and direct your attention to highly used code sections. Evaluate issues like:

[Tip]Tip
Use optimizing compilers and turn on suitable optimization flags.
[Tip]Tip
Avoid unnecessary work by caching data
[Tip]Tip
Use the correct algorithms
[Tip]Tip
Consider favoring algorithms that touch data sequentially
[Tip]Tip
Help the compiler by rearranging loops and introducing temporary variables
[Tip]Tip
Judiciously break encapsulation to avoid copying data