使用 getTickCount
頭文件 #include<time.h>
C++ 程序:
double t = (double)getTickCount();
// do something ...
t = ((double)getTickCount() - t)/getTickFrequency();
cout << "Times passed in seconds: " << t << endl;
C 程序:
clock_t start, finish;
double totaltime;
start = clock();
//do something ...
finish = clock();
totaltime = (double)(finish - start) / CLOCKS_PER_SEC;
printf("Time passed in seconds: %f\n", totaltime);
使用 time
命令
示例:
/nfsroot/opencv_test # time ./time
Times passed in seconds: 4.55756
real 0m 4.61s
user 0m 4.27s
sys 0m 0.02s
可以大致認爲程序執行的時間是 user 加上 sys ,其中 real 時間大於我們打印出來的程序執行時間是因爲程序在執行時有系統阻塞,系統暫時去執行其他任務了。