计算一个函数运行所需时间

#include<iostream>
#include<ctime>
using namespace std;
clock_t start, stop;
double duration;
void MyFunction()
{
int x = 0;
for (int i = 0; i < 1000000000; i++)
{
x++;
}
}
int main()
{
start = clock();
MyFunction();
stop = clock();
duration = ((double)(stop - start)) / CLK_TCK;
cout << duration;
return 0;
}

猜你喜欢

转载自blog.csdn.net/a66666_/article/details/80928071