目录

OpenCV-Python 获取一段代码运行的所消耗的时间

在图像处理中,由于您每秒处理大量操作,因此您的代码不仅要提供正确的解决方案,而且还要以最快的方式提供解决方案,通过 OpenCV 自带的函数可以进行时间差计算,示例代码如下:

import cv2 as cv

# 获取当前时间(1)
e1 = cv.getTickCount()

# 你的一些耗时的代码
for i in range(10000):
    print(i)

# 获取当前时间(2)
e2 = cv.getTickCount()
# 计算时间差
time = (e2 - e1) / cv.getTickFrequency()

# 打印耗时
print('耗时(秒)',time)

运行效果如下:

....
9996
9997
9998
9999
耗时(秒) 0.6926358


上一篇:«

下一篇: »


评论


Warning: Undefined variable $req in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 232

Warning: Undefined variable $commenter in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 233

Warning: Trying to access array offset on value of type null in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 233

Warning: Undefined variable $aria_req in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 233

Warning: Undefined variable $req in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 236

Warning: Undefined variable $commenter in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 237

Warning: Trying to access array offset on value of type null in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 237

Warning: Undefined variable $aria_req in /www/wwwroot/wxzzz.com/wp-content/themes/quirk-wordpress-theme-master/functions.php on line 238

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注