我使用以下代码,输出3个时钟的稳定状态
#include <chrono>
#include <iostream>
#include <iomanip>
template <typename C>
void printClockData ()
{
using namespace std;
cout << "- precision: ";
// if time unit is less or equal one millisecond
typedef typename C::period P;// type of time unit
if (ratio_less_equal<P,milli>::value) {
// convert to and print as milliseconds
typedef typename ratio_multiply<P,kilo>::type TT;
cout << fixed << double(TT::num)/TT::den
<< " milliseconds" << endl;
}
else {
// print as seconds
cout << fixed << double(P::num)/P::den << " seconds" << endl;
}
cout << "- is_steady: " << boolalpha << C::is_steady << endl;
}
int main()
{
std::cout << "system_clock: " << std::endl;
printClockData<std::chrono::system_clock>();
std::cout << "\nhigh_resolution_clock: " << std::endl;
printClockData<std::chrono::high_resolution_clock>();
std::cout << "\nsteady_clock: " << std::endl;
printClockData<std::chrono::steady_clock>();
}
用g ++编译,输出
使用intel icl输出进行编译
为什么会有差异?
答案 0 :(得分:2)
是的,是high_resolution_clock
。正如C ++标准所说:
20.12.7.3班级
high_resolution_clock
类
high_resolution_clock
的对象表示具有最短刻度周期的时钟。high_resolution_clock
可能是system_clock
或steady_clock
的同义词。
例如,Visual C++ 2015将typedef改为steady_clock
,英特尔也可能。{/ p>
对于steady_clock
,标准明确将is_steady
设置为true。