Linux/Unix/Posix是否为用户空间应用程序提供API以访问单调增加的时钟,精度为厘秒到毫秒?
在Linux上,/ proc/uptime提供了一个基于字符串的表示形式,表示系统启动的秒数的浮点数.
gettimeofday(2)不提供单调增加的时钟.
我可以在ITIMER_REAL时域中使用getitimer(2),将计时器设置为以(平台相关的)最大值开始并忽略生成的信号,但根据手册页,计时器可以运行的最长时间大约为100天,比我预期的运行时间短.
当我减去endTime - startTime时,我的macbook pro上的boost chrono library vs1.51返回负数.如果打印时间点,则会看到结束时间早于startTime.怎么会发生这种情况?
typedef boost::chrono::steady_clock clock_t;
clock_t clock;
// Start time measurement
boost::chrono::time_point<clock_t> startTime = clock.now();
short test_times = 7;
// Spend some time...
for ( int i=0; i<test_times; ++i )
{
xnodeptr spResultDoc=parser.parse(inputSrc);
xstring sXmlResult = spResultDoc->str();
const char16_t* szDbg = sXmlResult.c_str();
BOOST_CHECK(spResultDoc->getNodeType()==xnode::DOCUMENT_NODE && sXmlResult == sXml);
}
// Stop time measurement
boost::chrono::time_point<clock_t> endTime = clock.now();
clock_t::duration elapsed( endTime - startTime);
std::cout << std::endl;
std::cout << "Now time: " << clock.now() << std::endl;
std::cout << …Run Code Online (Sandbox Code Playgroud)