当前位置: 首页>>代码示例>>C++>>正文


C++ TimeInterval::seconds方法代码示例

本文整理汇总了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);
开发者ID:,项目名称:,代码行数:67,代码来源:


注:本文中的TimeInterval::seconds方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。