Optimization Strategies
Optimization of code can be done in several ways, such as the following:
- Compiler-based optimization
- Source code micro-optimization
- Cache-friendly code
- Algorithmic optimization
Here, each technique has its pros and cons. We will examine each of these methods in detail in the upcoming sections. Roughly speaking, these are ordered in terms of effort required and also potential gains in performance. We'll look at compiler-based optimization in the next section.
Compiler-Based Optimization
Passing the correct options to the compiler can net many performance benefits. A real-world example of this is the Clear Linux distro (Linux distribution) that was created by Intel. This distro has been compiled to extract the maximum performance from all the code and outperforms most other Linux distributions by 30% on most benchmarks, which is a very significant speedup. On the gcc and clang family of compilers, the most basic option for optimization is -O<...