C ++ run-time calculation program

#include <chrono>
int main()
{
auto start = std::chrono::steady_clock::now();
//
//需要被计算运行时间的程序
//
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double, std::milli> elapsed = end - start; // std::micro 表示以微秒为时间单位, std::milli 表示以毫秒为时间单位。
std::cout<< "time: "  << elapsed.count()<< "ms" << std::endl;
}

Editor: running time of the program in C ++ is calculated
here are devoted to chrono articles: c ++ 11 chrono comprehensive analysis (up to nanosecond-level precision)

Ka.
Published 23 original articles · won praise 7 · views 10000 +

Guess you like

Origin blog.csdn.net/guaiderzhu1314/article/details/97115280