A practical guide to optimising modern C++ code.

“Premature optimization is the root of all evil…”

– Donald Knuth, from his 1974 Turing Award lecture

Programmers have spent far too much time worrying about efficiency in the wrong places and at the wrong times. Premature optimization is the root of all evil (or at least most of it) in programming.

Describes both the process to perform performance tuning - use profiling tools to find the hotspots in an application, then benchmark before and after making optimisation changes as well as a number of tips when using different types of code.

All tips are benchmarked, with the proviso that results can and will change with different compilers and indeed between different versions of the same compiler. This is demonstrated in many of the included results. Results are provided for the more recent versions of the Visual C++ compiler, would have liked to have seen results for GCC too, but understand that this would have required a lot of extra work.

For me the main takeaways from the book, were to and to not make too many assumptions about the performance characteristics of existing code. On a number of occasions, the author was surprised by the performance characteristics of different approaches, particularly around different STL container classes when searching. This definitely provided me with some food for thought.

Optimized C++ by Gunneroth, published by O'Reilly