方法一:
#include<windows.h>
class MvTimer
{
public:
MvTimer() { QueryPerformanceFrequency(&Freq); restart(); }
void restart() { QueryPerformanceCounter(&Count1); }
float time() { QueryPerformanceCounter(&Count2); return (float)((Count2.QuadPart - Count1.QuadPart) / (double)Freq.QuadPart * 1000.0f); }
private:
LARGE_INTEGER Count1, Count2, Freq;
};
MvTimer t; t.restart(); f(); t.time(); //得到运行毫秒
cout << "The timeconsuming is "<< t.time() << "ms" << endl;
方法二:
//#include <Windows.h>
LARGE_INTEGER freq;
LARGE_INTEGER startTime;
LARGE_INTEGER stopTime;
double time;
QueryPerformanceFrequency(&freq);
QueryPerformanceCounter(&startTime);//开始计时
QueryPerformanceCounter(&stopTime);
time = 1e3*(stopTime.QuadPart - startTime.QuadPart) / freq.QuadPart;
cout << "你电脑的频率为:" << freq.QuadPart << endl;
cout << "opencv库函数消耗时间为:" << time << "毫秒" << endl;