C++11 定义high_resolution_clock
并且它具有成员类型period
和rep
. 但我不知道如何才能获得那个时钟的精度。
或者,如果我可能无法达到精确度,我能否以某种方式至少获得以纳秒为单位的最小可表示时间间隔的计数?可能使用period
?
#include <iostream>
#include <chrono>
void printPrec() {
std::chrono::high_resolution_clock::rep x = 1;
// this is not the correct way to initialize 'period':
//high_resolution_clock::period y = 1;
std::cout << "The smallest period is "
<< /* what to do with 'x' or 'y' here? */
<< " nanos\n";
}