In this example, we will create a simple benchmark using high_resolution_clock{}. To accomplish this, the following inclusions and namespaces are needed:
#include <chrono>
#include <iostream>
#include <gsl/gsl>
To create a benchmark function, we use the following:
template<typename FUNC>
auto benchmark(FUNC func) {
auto stime = std::chrono::high_resolution_clock::now();
func();
auto etime = std::chrono::high_resolution_clock::now();
return etime - stime;
}
This function has been seen before in Chapter 8, Learning to Program File Input/Output, The Logger Example. This code leverages functional programming to wrap a function call (likely a lambda) between two calls to the high-resolution clock. The results are then subtracted and returned. As we learned in this chapter, high_resolution_clock{} returns a...