欢迎访问 生活随笔!

生活随笔

当前位置: 首页 >

【CPP 小技巧 (一)FPS】统计处理一张图像算法消耗的时间 3 种方法

发布时间:2023/12/15 30 豆豆
生活随笔 收集整理的这篇文章主要介绍了 【CPP 小技巧 (一)FPS】统计处理一张图像算法消耗的时间 3 种方法 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

方法一:使用chrono 

#include <iostream> // std::cout #include <chrono> using namespace std; int main () {std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now();............auto t2 = std::chrono::steady_clock::now();std::chrono::duration<double> time_span = std::chrono::duration_cast<std::chrono::duration<double>>(t2 - now);std::cout << "It took me " << time_span.count() << " seconds." << std::endl;return 0; }

 方法二:使用opencv自带的getTickCount()和getTickFrequency()函数进行统计时间

double t1 = (double)getTickCount(); ............ double t2 = (double)getTickCount(); cout<<"time:"<<(t2-t1)*1000/(getTickFrequency())<<endl;

PS: 方法一和方法二统计的时间相差不大,任选其中一种方法作为自己的常用方法即可。

方法三:使用time.h提供的clock()进行时间统计,但是与前两种方法相比较,这种方法有时候统计得到的时间存在不准确的问题,有时候会比上述两种方法多一倍时间,所以不建议使用。 

#include "time.h"int main() {clock_t start = clock();............clock_t end = clock();double time = (double)(end-start)/CLOCKS_PER_SEC;std::cout << "time: " << time << std::endl; }

 

总结

以上是生活随笔为你收集整理的【CPP 小技巧 (一)FPS】统计处理一张图像算法消耗的时间 3 种方法的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。