首先上代码
比较两种计算时间方法:
GetTickcount函数:它返回从操作系统启动到当前所经的计时周期数。
getTickFrequency函数:返回每秒的计时周期数。
#include <iostream>
#include <string>
#include <fstream>
#include <omp.h> //开启多核cpu计算模式
#include <cv.h>
using namespace std;
using namespace cv;
int main()
{
double t1=(double)getTickCount();
cout<<"t1 ="<<t1<<endl;
int sum=0;
for(int i=0;i<10000;i++)
{
sum+=i;
}
double t2=(double)getTickCount();
cout<<"t2 ="<<t2<<endl;
double time = (t2-t1)/getTickFrequency();
cout<<"Time = "<<time<<endl;
int64 e1 = getTickCount();
cout<<"e1 ="<<e1<<endl;
int sum1=0;
for(int i=0;i<10000;i++)
{
sum1+=i;
}
int64 e2 = getTickCount();
cout<<"e2 ="<<e2<<endl;
double time1 = (e2-e1)/getTickFrequency();
cout<<"time1 ="<<time1<<endl;
system("pause");
return 0;
}
代码结果: