Optimized C++: Proven Techniques for Heightened Performance 1st Edition
Use the Amazon App to scan ISBNs and compare prices.
"Devoted" by Dean Koontz
For the first time in paperback, from Dean Koontz, the master of suspense, comes an epic thriller about a terrifying killer and the singular compassion it will take to defeat him. | Learn more
Enter your mobile number or email address below and we'll send you a link to download the free Kindle App. Then you can start reading Kindle books on your smartphone, tablet, or computer - no Kindle device required.
To get the free app, enter your mobile phone number.
Frequently bought together
Customers who viewed this item also viewed
About the Author
A career technologist with broad experience in software development, Kurt has exceptional experience and skills in early stages of product development including market research, user needs analysis, and architectural design. In addition, Kurt has very deep C++ development experience. He currently works as a Software Engineer at iStreamPlanet.
- Item Weight : 1.5 pounds
- Paperback : 388 pages
- ISBN-10 : 9781491922064
- ISBN-13 : 978-1491922064
- Product Dimensions : 7 x 0.88 x 9.2 inches
- Publisher : O'Reilly Media; 1st edition (May 24, 2016)
- Language: : English
- ASIN : 1491922060
- Best Sellers Rank: #687,266 in Books (See Top 100 in Books)
- Customer Reviews:
Top reviews from the United States
There was a problem filtering reviews right now. Please try again later.
A few concepts I was hoping for are missing, including vectorization (SSE, AVX), which is mentioned only in passing; more depth to floating point arithmetic; better discussion of memory and cache access patterns (the handling of the CPU cache in particular is so vague that there's no takeaway message that I could apply to my code); ...
Meanwhile, there's an excessive amount of time spent on a handful of topics, including timers (why are sundials and grandfather clocks given full paragraphs?) and, as others have said, the C++ language itself.
I was hoping this book would be a reference guide once I'd finished reading it, but a lot of the material wasn't quite concrete enough for it to be useful. I would highly recommend reading Agner's manuals instead if you have knowledge of C++ already. In some places they're a little bit dated but still solid and very much grounded in computer architecture. (Do a search, they're free online.)
1. It is really for people who does not know C++. Literally half of the book is explanation what is std::string and” don’t do too much in the loop”.
2. It seems to me author himself does not understand relatively basic things about C++ optimization ( e.g. why binary search on sorted array could be faster than hash map ). Some statement such as “always move declaration of a variable out of the loop” is just incorrect.
Advise for beginners – don’t buy this book. Learn from experts: Scott Meyers, Nicolai M. Josuttis, Antony Williams, Andrei Alexandrescu, Herb Sutter …
OTOH, sometimes this real experience is a bit, well, stale. For example, for measuring time intervals the book states that "on PCs, the fastest tick counters available have 100-nanosecond resolution" - which isn't true even for Windows which corresponding section heavily leans to (there is RDTSC instruction with ~1ns resolution for about 20 years now on all what can be named PC). In another example, in the whole chapter dedicated to strings I didn't find a reference to Small String Optimization (SSO), which is a reality for 5+ years now, and which changes performance analysis significantly. Advice "perform I/O in a separate thread" is also outdated in the modern days of generally-better-performing async I/O (at the very least, async I/O should be mentioned in this context).
Overall, I'd give this book 3.5 stars, but there is no such option - and given that books with real-world experience are rare, I decided to round it up rather than down.
Top reviews from other countries
First, the author writes extensively (probably about half of the book in total) on basic C++ concepts that most readers should already know and/or concepts that are irrelevant to the topic of the book.
Second, when the author tries to provide potentially useful information, he discusses the topic in an inadequate way that is likely to leave readers scratching their heads in confusion.
Third, more than a few times the author wrote something that I knew to be incorrect or misleading.
Here are some examples of those second and third problems...
On pages 84-85, the author advocates the use of std::stringstream, but neglects to mention that this class performs lots of work in its constructor (apparently something to do with locales). I once obtained a significant optimisation in an application by removing as many instances of stringsteam as I could.
On page 97, the author advocates use of hash tables but neglects to mention that the heap allocation used in most hash table implementations is likely to increase cache misses (and hence reduce performance). He neglects to mention that there are some implementations of hash tables that use a large block of contiguous memory to be more cache friendly. (Do an Internet search for "flat hashmap" if you are interested in efficient hash tables.) The author mentions that a hash table lookup is O(1) in the common case and O(N) in the worst case, but never mentions the possibility of using a DFA, which is always O(1) lookup. Put simply, a DFA can be faster than a hash table, and this contradicts the author's claim that hash tables provide the fastest table lookup mechanism. The discussion on page 97 about hash tables would have benefited from mentioning the possibility of perfect hashes, but readers have to wait more than 100 pages (until page 224) for a mention of this.
On pages 123-124, the author mentions the possibility of storing a balanced binary tree in a contiguous array rather than in fragmented heap-allocated memory. This is a potentially useful thing to know but, unfortunately, the discussion of this topic is too superficial to be useful. In addition, he conflates two different opportunities for optimisation---(a) using a continuous array to avoid fragmented heap-allocated memory, and (b) using implicitly computed pointers/indexes rather than explicit pointers to parent/child nodes---into a single discussion and gives the incorrect impression that you must combine both opportunities together.
On page 150, the author mentions the possibility of iterating over an array backwards (that is, from length-1 to 0) rather than forwards (from 0 to length-1), but he neglects to warn that iterating backwards might be slower due to some CPUs implementing a forwards-looking-only cache prefetching mechanism. On my Intel-based laptop, iterating backwards over a multi MB array takes 25% more time than iterating forwards.
On pages 233-234, the author uses low-resolution timers to do a high-resolution performance test. The author tries to explain why this should work, but the explanation is too superficial and left me dubious.
On page 245, the author claims that, in most cases, the relative performance of two apps/algorithms when compiling in debug mode is similar to the relative performance when compiling in release/optimised mode. I was shocked at the author's naivety when I read this claim.
In summary, the book provides very little useful insight but lots of waffle and too much incorrect/bad advice to be recommended. Part-way through reading this book, I found a much better book called "Optimizing software in C++: An optimization guide for Windows, Linux and Mac platforms". You can find a free PDF of that book with an Internet search. It contains about half the pages and 10 times more insight than "Optimized C++".
There is some interesting discussion of some C++-specific aspects, but not often in a very thorough or consistent manner. In the chapter about standard containers, the author gives a bunch of performance figures measured with some benchmark of his own, but the source code for the benchmark is unavailable, so you cannot try with your own compiler and standard library. Knowing that this or that has lackluster performance on Visual Studio 2015 doesn't help much if I'm targetting gcc 6 with the GNU libstdc++ on Linux.
In the part about memory management, there is this very vague statement "I have heard a rumor that both Windows and Linux have recently raised their game with state-of-the-art memory managers". Well... ok, you've heard a rumor, but you're writing and selling a book about optimized C++, so perhaps you should have gone and validate what the rumor says? I don't buy a specialized, technical book to learn about unconfirmed rumors!
As a more minor issue, I'm surprised that the author spends time discussing pre-C++11 idioms. This, in a book published in 2016.
I'm not a veteran C++ programmer, yet I feel I learnt too little by reading this book.