本文整理汇总了C++中TimeUnit::count方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeUnit::count方法的具体用法?C++ TimeUnit::count怎么用?C++ TimeUnit::count使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeUnit
的用法示例。
在下文中一共展示了TimeUnit::count方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: getElapsed
// TODO: USE idx INSTEAD OF size_t
size_t getElapsed()
{
/*!
* Returns elapsed time as number of ticks of TimeUnits
* Elapsed time can mean 2 different things:
*
* 1. If TickCounter is running, elapsed time is measured between starTime
* and now.
* 2. If TickCounter is not running (i.e. it is stopped), elapsed time
* is measured between startTime and stopTime.
*/
// DIFFERENCE BETWEEN THE TWO "TIMEPOINTS" MUST BE CAST TO
// A "DURATION" USING THE std::chrono::duration_cast
TimeUnit duration;
// CASE 1 - TickCounter IS RUNNING, USE CURRENT TIME
if (isRunning)
{
duration = std::chrono::duration_cast <TimeUnit>
( std::chrono::high_resolution_clock::now() - startTime );
}
// CASE 2 - NOT RUNNING, USE stopTime
else
{
duration = std::chrono::duration_cast<TimeUnit>
(stopTime - startTime);
}
// CAST TO TICK COUNT
return static_cast <size_t> ( duration.count() );
}