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


C++ Stopwatch::elapsedTime方法代码示例

本文整理汇总了C++中Stopwatch::elapsedTime方法的典型用法代码示例。如果您正苦于以下问题:C++ Stopwatch::elapsedTime方法的具体用法?C++ Stopwatch::elapsedTime怎么用?C++ Stopwatch::elapsedTime使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Stopwatch的用法示例。


在下文中一共展示了Stopwatch::elapsedTime方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: onRender

void App::onRender() {
    // Show message
    message("Rendering...");

    Stopwatch timer;
    rayTraceImage(1.0f, m_raysPerPixel);
    timer.after("Trace");
    debugPrintf("%f s\n", timer.elapsedTime());
//    m_result->toImage3uint8()->save("result.png");
}
开发者ID:tylerwolverton,项目名称:CS-334,代码行数:10,代码来源:App.cpp

示例2: main


//.........这里部分代码省略.........
        //:
        //: 4 That 'elaspsedTime' returns the correct elapsed time in
        //:   nanoseconds.
        //:
        //: 5 That 'reset' resets the 'Stopwatch' to its defualt constructed
        //:   state.
        //
        // Plan:
        //: 1 Construct a 'Stopwatch' and verify 'isRunning' is 'false' and
        //:   'elapsedTime' is 0. (C-1)
        //:
        //: 2 Construct a 'Stopwatch', call 'start', sleep for ~1 second and
        //:   verify 'isRunning' it 'true' and 'elapsedTime' is ~1 second.
        //:
        //: 2 Construct a 'Stopwatch', call 'start', sleep for ~1 second and
        //:   then stop the 'Stopwatch'.  Sleep another second. Verify
        //:   'isRunning' it 'false', 'elapsedTime' is ~1, and that the elapsed
        //:   time has not changed since the stopwatch was stopped.
        //
        // Testing:
        //   TESTING TEST-MACHINERY: 'Stopwatch'
        // --------------------------------------------------------------------

        if (verbose) printf("\nTESTING TEST-MACHINERY: 'Stopwatch'"
                            "\n===================================\n");

        const double TOLERANCE = .5;

        if (veryVerbose) printf("\tCompare constructed 'Stopwatch'\n");
        {
            Stopwatch mX; const Stopwatch& X = mX;

            ASSERT(false == X.isRunning());
            ASSERT(0     == X.elapsedTime());
        }

        if (veryVerbose) printf("Test starting a stopwatch\n");
        {
            Stopwatch mX; const Stopwatch& X = mX;

            ASSERT(false == X.isRunning());
            ASSERT(0     == X.elapsedTime());

            mX.start();
            sleep(1);

            ASSERT(true  == X.isRunning());
            ASSERT(1 - TOLERANCE <  X.elapsedTime());
            ASSERT(1 + TOLERANCE >  X.elapsedTime());
        }

        if (veryVerbose) printf("Test stop and elapsedTime\n");
        {
            Stopwatch mX; const Stopwatch& X = mX;

            ASSERT(false == X.isRunning());
            ASSERT(0     == X.elapsedTime());

            mX.start();
            sleep(1);

            ASSERT(true  == X.isRunning());
            ASSERT(0     <  X.elapsedTime());

            mX.stop();
开发者ID:che2,项目名称:bde,代码行数:66,代码来源:bsls_performancehint.t.cpp

示例3: testReorderingFence

void testReorderingFence(int argc)
{
    int verbose = argc > 2;
    int veryVerbose = argc > 3;
    int veryVeryVerbose = argc > 4;

    // suppress 'unused parameter' compiler warnings:
    (void) verbose;
    (void) veryVeryVerbose;

    enum {
        CHUNK_SIZE = 1000
    };
    double    rateWithFence;
    double    rateWithoutFence;

    if (veryVerbose) {
        printf("With BSLS_PERFORMANCEHINT_OPTIMIZATION_FENCE\n");
    }
    {
        Stopwatch timer;
        timer.start();

        double elapsedTime = 0;
        int    iterations  = 0;
        int    numChunks   = 0;
        while (elapsedTime <= .4) {
            for (int i = 0; i < CHUNK_SIZE; ++i) {
                iterations++;
                BSLS_PERFORMANCEHINT_OPTIMIZATION_FENCE;
            }
            ++numChunks;
            elapsedTime = timer.elapsedTime();
        }

        rateWithFence = numChunks/elapsedTime;
    }

    if (veryVerbose) {
        printf("\trate = %f\n", rateWithFence);
    }


    if (veryVerbose) {
        printf("Without BSLS_PERFORMANCEHINT_OPTIMIZATION_FENCE\n");
    }
    {
        Stopwatch timer;
        timer.start();

        double elapsedTime = 0;
        int    iterations  = 0;
        int    numChunks   = 0;
        while (elapsedTime <= .4) {
            for (int i = 0; i < CHUNK_SIZE; ++i) {
                iterations++;
            }
            ++numChunks;
            elapsedTime = timer.elapsedTime();
        }

        rateWithoutFence = numChunks/elapsedTime;
    }
    if (veryVerbose) {
        printf("\trate = %f\n", rateWithoutFence);
    }

#if defined(BDE_BUILD_TARGET_OPT) &&                                          \
  !(defined(BSLS_PLATFORM_CMP_SUN) && (BSLS_PLATFORM_CMP_VERSION < 0x5110))

    // Perform this test only for optimized builds.  Also older Sun compilers
    // do not support this fence.

    LOOP2_ASSERT(rateWithFence, rateWithoutFence,
                 rateWithFence < rateWithoutFence);
#endif
}
开发者ID:che2,项目名称:bde,代码行数:77,代码来源:bsls_performancehint.t.cpp

示例4: testUsageExample3

void testUsageExample3(int argc, bool assert)
{
    int verbose = argc > 2;
    int veryVerbose = argc > 3;
    int veryVeryVerbose = argc > 4;

    // suppress 'unused parameter' compiler warnings:
    (void) assert;
    (void) verbose;
    (void) veryVeryVerbose;

    if (veryVerbose) {
        printf("Adding without prefetch\n");
    }

    UsageExample3Case::init(UsageExample3Case::array1,
                            UsageExample3Case::array2);

    Stopwatch timer;
    timer.start();

    for(int i = 0; i < TESTSIZE; ++i) {
        UsageExample3Case::addWithoutPrefetch(UsageExample3Case::array1,
                                              UsageExample3Case::array2);
    }

    timer.stop();
    double withoutPrefetch = timer.elapsedTime();

    if (veryVerbose) {
        P(withoutPrefetch);
    }

    if (veryVerbose) {
        printf("Adding with prefetch\n");
    }

    UsageExample3Case::init(UsageExample3Case::array3,
                            UsageExample3Case::array4);

    timer.reset();
    timer.start();

    for(int i = 0; i < UsageExample3Case::TESTSIZE; ++i) {
        addWithPrefetch(array3, array4);
    }

    timer.stop();
    double withPrefetch = timer.elapsedTime();

    if (veryVerbose) {
        P(withPrefetch);
    }

#if defined(BDE_BUILD_TARGET_OPT)
    // Only check under optimized build.

#if defined(BSLS_PLATFORM_CMP_CLANG)                                          \
 || defined(BSLS_PLATFORM_CMP_GNU)                                            \
 || defined(BSLS_PLATFORM_CMP_SUN)                                            \
 || defined(BSLS_PLATFORM_CMP_IBM)                                            \
 || defined(BSLS_PLATFORM_OS_WINDOWS)
    // Only check when 'prefetchForReading' or 'prefetchForWriting' expands
    // expands into something meaningful.

    double tolerance = 0.02;

    // Note that when compiling using 'bde_build.pl -t opt_exc_mt', the
    // optimization flag is set to '-O'.  Whereas, the optimization flag used
    // by 'IS_OPTIMIZED=1 pcomp' is set to '-xO2'.  Therefore, the improvement
    // in efficiency is much less than what's described in the usage example
    // when compiled using bde_build.

    if (assert) {
        // Only assert in performance test case.
        LOOP2_ASSERT(withoutPrefetch, withPrefetch,
                     withoutPrefetch + tolerance > withPrefetch);
    }

#endif

#endif

}
开发者ID:che2,项目名称:bde,代码行数:84,代码来源:bsls_performancehint.t.cpp

示例5: testUsageExample1

void testUsageExample1(int argc, bool assert)
{
    int verbose = argc > 2;
    int veryVerbose = argc > 3;
    int veryVeryVerbose = argc > 4;

    double tolerance = 0.05;

    (void) assert;
    (void) verbose;
    (void) veryVerbose;
    (void) veryVeryVerbose;
    (void) tolerance;

    Stopwatch timer;

    timer.reset();

    if (veryVerbose) {
        printf("BSLS_PERFORMANCEHINT_PREDICT_LIKELY\n");
    }

    timer.start();

    for (int x = 0; x < TESTSIZE; ++x) {
        int y = rand() % 100;

        // Incorrect usage of 'BSLS_PERFORMANCEHINT_PREDICT_LIKELY' since there
        // is only a one in 100 chance that this branch is taken.

        if (BSLS_PERFORMANCEHINT_PREDICT_LIKELY(y == 8)) {
            foo();
        }
        else {
            BSLS_PERFORMANCEHINT_UNLIKELY_HINT;
            bar();
        }
    }

    timer.stop();
    double likelyTime = timer.elapsedTime();

    if (veryVerbose) {
        P(likelyTime);
    }


    if (veryVerbose) {
        printf("BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY\n");
    }

    timer.reset();
    timer.start();

    for (int x = 0; x < TESTSIZE; ++x) {
        int y = rand() % 100;

        // Correct usage of 'BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY' since there
        // is only a one in 100 chance that this branch is taken.

        if (BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY(y == 8)) {
            BSLS_PERFORMANCEHINT_UNLIKELY_HINT;
            foo();
        }
        else {
            bar();
        }
    }
    timer.stop();
    double unlikelyTime = timer.elapsedTime();

    if (veryVerbose) {
        P(unlikelyTime);
    }

#if defined(BDE_BUILD_TARGET_OPT)
    // Only check under optimized build.

#if defined(BSLS_PLATFORM_CMP_CLANG)                                          \
 || defined(BSLS_PLATFORM_CMP_GNU)                                            \
 || defined(BSLS_PLATFORM_CMP_SUN)                                            \
 || (defined(BSLS_PLATFORM_CMP_IBM) && BSLS_PLATFORM_CMP_VERSION >= 0x0900)
    // Only check when 'BSLS_PERFORMANCEHINT_PREDICT_LIKELY' and
    // 'BSLS_PERFORMANCEHINT_PREDICT_UNLIKELY' expands into something
    // meaningful.

    if (assert) {
        LOOP2_ASSERT(likelyTime, unlikelyTime,
                     likelyTime + tolerance > unlikelyTime);
    }

#endif

#endif

}
开发者ID:che2,项目名称:bde,代码行数:96,代码来源:bsls_performancehint.t.cpp


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