c++ visual studio10编译后,如何让它显示计算时间

c++ visual studio10 After compiling, how do i make it so that it displays the calculation time

不知道你怎么称呼的..你用visual studio10编译后黑屏显示结果

我在 youtube 视频上注意到,在他们的屏幕上,它还显示了计算所花费的时间。(不是编译时间)

我很确定答案就在那里,但我不知道要搜索的关键字..

一个小例子:

omp_get_wtime

#include <omp.h>

int main(void)
{
    double dStart = omp_get_wtime();

    Calculations();

    double dEnd = omp_get_wtime();

    std::cout << "Calculation took: " << dEnd - dStart << " sec." std::endl;

    return 0;
}

这是我用来计时的小秒表class。准确性是......好吧......你做的工作越多越好,这样说吧。

    #include <sstream>
    #include <chrono>

    class Stopwatch final
    {
    public:

        Stopwatch()
        {
            Reset();
        }

        void Reset()
        {
            MyCurrentTime = MyClock.now();
        }

        double Elapsed() const
        {
            auto elapsed = std::chrono::duration_cast<std::chrono::duration<double>>(MyClock.now() - MyCurrentTime);

            return elapsed.count();
        }

        int ms() const
        {
            return static_cast<int>(0.5 + Elapsed() * 1000);
        }

        std::string ToMilliseconds() const
        {
            auto o = std::ostringstream();

            o << ms();

            return o.str();
        }

        std::string ToSeconds(int precision) const
        {
            auto o = std::ostringstream();

            o.precision(precision);

            o << std::fixed << Elapsed();

            return o.str();
        }

    private:

        std::chrono::high_resolution_clock MyClock;
        std::chrono::high_resolution_clock::time_point MyCurrentTime;
    };