REVIEW - C++ High Performance, 2nd Edition - Master the Art of Optimizing the Functioning of Your C++ Code


Title:

C++ High Performance, 2nd Edition

Master the Art of Optimizing the Functioning of Your C++ Code

Author:

Bjorn Andrist, Viktor Sehr

Publisher:

Packt (2020)

Pages:

502

Reviewer:

Paul Floyd

Reviewed:

September 2023

Rating:

★★★★★


Verdict: Highly recommended

The title of this book is slightly misleading. With so many books on the market, there aren’t that many snappy titles left. I would say that this is more of a General C++ Overview with an Emphasis on Performance. But I understand why Packt didn’t want something like that.

The prose is clear, I liked the layout and there are a good number of well-drawn diagrams. I barely noticed any errors.

There are 15 chapters covering the basics, data structures, algorithms, memory, templates, caching, concurrency and coroutines. That’s an awful lot to cover in only 500 pages and I think that they did a pretty good job. Some parts were a bit weak – I’ve read better explanations of threading issues.

Overall, for beginner to medium-level programmer, I’d say this is one of the better books that I’ve read, especially if performance is important for you (and it usually is for C++ developers).

Whilst examples in books like this are not meant for production code, one snippet bothered me because it was so bad. It’s part of a safe_cast supposedly checking that various types are safe to cast to each other. The bit for floating point is

      else if constexpr (
          is_float_to_float) {
        auto casted 
          = static_cast<OutType>(v);
        auto casted_back 
          = static_cast<InType>(v);
        assert(!isnan(casted_back) &&
          !isinf(casted_back));
        return casted;
      }

where is_float_to_float is true when InType and OutType are both is_floating_point_v. I’ll ignore long double.

  1. It’s always safe to promote float to double (and this gets done all the time behind the scenes).
  2. If floating point exceptions are enabled this will generate a SIGFPE and possibly crash if the casting results in underflow, overflow and maybe an invalid operation.
  3. Why assert on nan?
  4. Why not accept inf input?
  5. I still don’t see any practical use for a conversion from double to float that is restricted to double values that can be exactly represented by a float.

Getting off my hobby horse, I still enjoyed the book a lot and took several notes that I want to go back over and test out. The authors have a github repo which will make that easier.

Website: https://www.packtpub.com/product/c-high-performance-second-edition/9781839216541






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.