In this recipe, you will learn how to benchmark and optimize your source code. Optimizing source code will result in more efficient C++, which increases battery life, improves performance, and so on. This recipe is important as the process of optimizing source code starts with determining which resource you plan to optimize, which could include speed, memory, and even power. Without benchmarking tools, it is extremely difficult to compare different approaches to the same problem.
There are countless benchmarking tools (anything that measures a single property of your program) available to C++ programmers, including C++ APIs such as Boost, Folly, and Abseil, and CPU-specific tools such as Intel's vTune. There are also several profiling tools (anything the helps you understand the behavior of your program) such as valgrind and gprof. In this recipe, we...