In previous chapters, we discussed how to benchmark software using various different mechanisms. In this chapter, we will explore creating our own high-resolution timer using a thread, instead of using the high-resolution timer provided by the C++ chrono APIs.
To accomplish this, we will create a thread with the sole job of counting as fast as possible. It should be noted that although this will provide a high-resolution timer that is extremely sensitive, it has a lot of disadvantages compared to computer architectures such as Intel. These provide hardware instructions with higher resolution than is possible here, while being less susceptible to CPU frequency scaling.
In this example, the following inclusion and namespaces are needed:
#include <thread>
#include <mutex>
#include <condition_variable>
#include <...