c++ 记录程序运行时间

低精度测量时间

头文件

#include 

程序:

clock_t start, end;

start = clock();
// 测试的程序

std::cout << "time consume: " << (double)(clock() - start) / CLOCKS_PER_SEC << std::endl;
   

高精度测量时间

#include 

auto startTime = std::chrono::high_resolution_clock::now();
// your code
auto endTime = std::chrono::high_resolution_clock::now();
float totalTime = std::chrono::duration
(endTime - startTime).count();

你可能感兴趣的:(c与c++)