C++11 定义high_resolution_clock
它有成员类型period
and 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";
}
最小可表示持续时间是high_resolution_clock::period::num / high_resolution_clock::period::den
秒。你可以像这样打印它:
std::cout << (double) std::chrono::high_resolution_clock::period::num
/ std::chrono::high_resolution_clock::period::den;
为什么是这样?一个时钟的::period
成员被定义为“时钟的滴答周期(以秒为单位)”。它是一个专业化std::ratio
这是一个在编译时表示比率的模板。它提供了两个积分常数:num
and den
,分别是分数的分子和分母。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)