本文整理汇总了C++中TimeInterval::seconds方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeInterval::seconds方法的具体用法?C++ TimeInterval::seconds怎么用?C++ TimeInterval::seconds使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TimeInterval
的用法示例。
在下文中一共展示了TimeInterval::seconds方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
//.........这里部分代码省略.........
//: the current wall clock time.
//:
//: 3 QoI: That consecutive values do not decrease (under normal
//: conditions).
//:
//: 4 QoI: The resolution of the real-time clock is < 1 second.
//
// Plan:
//: 1 Call 'nowRealtimeClock' and verify the value returned, when
//: treated as an interval from the Unix epoch, corresponds to a
//: possible wall clock time. (C-1)
//:
//: 2 Call 'nowRealtimeClock' and compare the value returned to an
//: oracle clock, i.e., the standard library function 'time'. (C-2)
//:
//: 3 Call 'nowRealtimeClock' in a loop for a couple seconds; verify
//: the results do not decrease between iterations, and that
//: increments of the clock are less than 1 second. (C-3..4)
//
// Testing:
// TimeInterval nowRealtimeClock();
// --------------------------------------------------------------------
if (verbose) printf("\nCLASS METHODS: 'nowRealtimeClock'"
"\n=================================\n");
if (veryVerbose) printf("\tTest result is relative to Unix epoch\n");
{
const int64_t SEPT_27_2014 = 1411833584;
const int64_t HUNDRED_YEARS_APPROX = 60ull * 60 * 24 * 365 * 100;
TimeInterval t = Obj::nowRealtimeClock();
ASSERT(SEPT_27_2014 <= t.seconds());
ASSERT(SEPT_27_2014 + HUNDRED_YEARS_APPROX >= t.seconds());
}
if (veryVerbose) printf("\tCompare results to 'time'\n");
{
time_t timeValue = time(0);
TimeInterval systemTimeValue = Obj::nowRealtimeClock();
ASSERT(timeValue - 1 <= systemTimeValue.seconds());
ASSERT(timeValue + 1 >= systemTimeValue.seconds());
}
if (veryVerbose) printf("\tVerify sequential values'\n");
{
// Test sequential values are increasing and have a resolution of
// less than 1 second.
TimeInterval ONE_SEC = TimeInterval(1, 0);
TimeInterval origin = Obj::nowRealtimeClock();
TimeInterval prev = origin;
TimeInterval now = origin;
while (TimeInterval(1.5) > now - origin) {
if (veryVerbose) {
P_(prev);
P(now);
}
now = Obj::nowRealtimeClock();
ASSERT(prev <= now);
ASSERT(prev + ONE_SEC > now);