C/C++中代码段运行时间/程序运行时间
程序员文章站
2022-05-26 22:28:51
...
include<iostream>
#include<ctime>
using namespace std;
int main()
{
clock_t startTime,endTime;
for (int i = 0; i < 2147483640; i++)
{
i++;
}
startTime = clock();//计时开始
for ( i = 0; i < 2147483640; i++)
{
i++;
}
endTime = clock();//计时结束
cout << "The run time is:" <<(double)(endTime - startTime) / CLOCKS_PER_SEC << "s" << endl;
cout << "The run time is:" << (double)clock() /CLOCKS_PER_SEC<< "s" << endl;
system("pause");
return 0;
}
上一篇: css水平垂直居中