Benchmarking your code

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 will focus on two of these: Hayai and Valgrind. Hayai provides a simple example of a micro-benchmarking, while Valgrind provides an example of a more complete, though more complicated, dynamic analysis/profiling tool.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset