What is the best, most accurate timer in C++?
In C++11 you can portably get to the highest resolution timer with:
#include
#include
#include "chrono_io"
int main()
{
typedef std::chrono::high_resolution_clock Clock;
auto t1 = Clock::now();
auto t2 = Clock::now();
std::cout << t2-t1 << '\n';
}
Example output:
74 nanoseconds
"chrono_io" is an extension to ease I/O issues with these new types and is freely available here.
There is also an implementation of available in boost (might still be on tip-of-trunk, not sure it has been released).