Measuring program performance using Boost Timer
As programmers, we often need to measure performance of a section of code. While there are several excellent profiling tools available for this purpose, sometimes, being able to instrument our own code is both simple and more precise. The Boost Timer library provides an easy-to-use, portable interface for measuring the execution times and reporting them by instrumenting your code. It is a separately compiled library, not header-only, and internally uses Boost Chrono.
cpu_timer
The
boost::timer::cpu_timer
class is used to measure the execution time of a section of code. In the following example, we write a function that reads the contents of a file and returns it in a dynamic array wrapped in a unique_ptr ...
Get Learning Boost C++ Libraries now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.