版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/baidu_28446365/article/details/89293006
1、常规测量
#include <ctime>//需包含的头文件
long ibegin = 0;
double iend = 0.0;
ibegin = clock();
//运行代码块
iend += (double)(clock() - ibegin) / CLOCKS_PER_SEC;//运行时间
cout << "iend:" << iend << endl;
ofstream infile;//打印到文件
infile.open("work.txt");
infile << iend << "\n";
//printf("\n ME Time: %12.3f sec.\n", iend);
infile.close();
2、高精度测量
#include <ratio>
#include <chrono>
using namespace std::chrono;
high_resolution_clock::time_point t1 = high_resolution_clock::now();
//运动代码块
high_resolution_clock::time_point t2 = high_resolution_clock::now();
duration<double, std::milli> time_span = t2 - t1;