Easily measure elapsed time

前端 未结 26 2152
栀梦
栀梦 2020-11-22 04:13

I am trying to use time() to measure various points of my program.

What I don\'t understand is why the values in the before and after are the same? I understand thi

26条回答
  •  孤街浪徒
    2020-11-22 04:49

    //***C++11 Style:***
    #include 
    
    std::chrono::steady_clock::time_point begin = std::chrono::steady_clock::now();
    std::chrono::steady_clock::time_point end = std::chrono::steady_clock::now();
    
    std::cout << "Time difference = " << std::chrono::duration_cast(end - begin).count() << "[µs]" << std::endl;
    std::cout << "Time difference = " << std::chrono::duration_cast (end - begin).count() << "[ns]" << std::endl;
    

提交回复
热议问题