2
试图以此来找到我的代码的执行时间:执行时间在C++中
#include <iostream>
#include <time.h>
using namespace std;
int main()
{
clock_t t1, t2;
t1 = clock();
// code goes here
t2 = clock();
float diff = ((float)t2 - (float)t1);
cout <<"Execution Time = "<<diff/CLOCKS_PER_SEC <<endl;
system ("pause");
return 0;
}
,但每次与相同的代码执行时会返回一个不同的时间。代码是否正确?
我想检查我的代码在不同情况下的执行时间,但不应该显示相同的时间,当我执行相同的代码两次?
时间不确定,对于这样短的操作,它可能相差很大。 –
它永远不会显示完全相同的时间。顺便说一句,尝试使用新的''函数来定时你的程序,看到一个例子[这里](http://en.cppreference.com/w/cpp/chrono/steady_clock/now)。 –
vsoftco
处理器还有哪些? –