Up to now, we listed the following classic optimization techniques:
- Optimal algorithms
- Optimal data structures
- Caching
- Precomputed tables
- Preallocation and custom allocators
- Buffering and batching
- Read-ahead
- Copy avoidance
- Finding a better library
With our current stand of knowledge, we can formulate the following general-performance optimization procedure:
- Write your code, avoiding unnecessary pessimizations where it doesn't cost much, as in the following examples:
- Pass parameters by reference.
- Use reasonably good, widely known algorithms and data structures.
- Avoid copying data and unnecessary allocations.
This alone should give you a pretty decent baseline performance.
- Measure the performance, ...