REVIEW - Optimized C++


Title:

Optimized C++

Author:

Kurt Guntheroth

Publisher:

O’Reilly (2016)

Pages:

366pp

Reviewer:

Paul Floyd

Reviewed:

July 2019

Rating:

★★★☆☆


I’ve always been an advocate of avoiding gratuitous premature pessimization (is it ever possible to mention optimization without quoting or paraphrasing Knuth/Hoare?). So this book was pretty much up my street. It’s well written, and I liked the fact that it uses C++11 – there’s no point in pandering to the laggards that are stuck in the last century. There are 13 chapters that cover an introduction, hardware and timing, algorithmic optimization, low level optimizations (code changes, memory use, I/O and threads) and memory management.

I enjoyed the coverage of timing, and in particular the limitations and evolution of the timing features available on x86 based systems. Another high point was the debunking of some myths like std::vector always being significantly faster than std::list , along with fairly wide ranging tests. However, this leads me to one of the weaknesses. Pretty much all of the testing was done with one compiler (MS Visual Studio) and platform. So without a wider range of platforms and compilers I found myself taking the results with a pinch of salt.

There were three things that struck me as missing. In Chapter 4, there is a lengthy discourse on optimizing a function that strips control characters from a string. One of the techniques used is pass by reference. This results in an 8% performance degradation, which is not explained in any way. I would expect a book like this to get to the bottom of such as issue. The second thing that is missing is detailed coverage of profiling tools. The author seems to prefer instrumenting code with timer calls, which is good enough, but I thought that there should have been some explanation of the different kinds of profilers and some example usage. Lastly, a lot is said about std::string and its performance not being great. However, there is no mention of the Short String Optimization (SSO). I was expecting some mention of it and perhaps characterizing the performance ‘knee’ is string lengths exceed the SSO threshold.

In summary I enjoyed reading this book and learned a few things but there were a few annoying nits.

Recommended.


Book cover image courtesy of Open Library.





Your Privacy

By clicking "Accept Non-Essential Cookies" you agree ACCU can store non-essential cookies on your device and disclose information in accordance with our Privacy Policy and Cookie Policy.

Current Setting: Non-Essential Cookies REJECTED


By clicking "Include Third Party Content" you agree ACCU can forward your IP address to third-party sites (such as YouTube) to enhance the information presented on this site, and that third-party sites may store cookies on your device.

Current Setting: Third Party Content EXCLUDED



Settings can be changed at any time from the Cookie Policy page.