1. 程式人生 > >OpenCV:計時函式getTickCount、getTickFrequency

OpenCV:計時函式getTickCount、getTickFrequency

1. getTickCount() & getTickFrequency()

getTickCount():返回CPU自某個時間以來走過的時鐘週期數。
getTickFrequency():返回CPU一秒中所走的時鐘週期數,因此可以以秒為單位對某運算時間計時。

double start = static_cast<double>(getTickCount());
double time = ((double)getTickCount() - start) / getTickFrequency();
cout << "run time: " << time << "s" << endl;

2. cvGetTickCount() & cvGetTickFrequency()

【注】:此時得到的單位是us級的統計時間。

 double start = static_cast<double>(cvGetTickCount());
 double time = ((double)cvGetTickCount() - start) / cvGetTickFrequency();
 cout << "run time: " << time << "us" << endl;