# cv2.getTickFrequency函数返回时钟频率或者每秒钟的时钟循环数# cv2.getTickCount 函数返回从一个参考时间(比如机器开机的时间)开始到这个函数被调用的时间之间的时钟循环数量。import cv2
import numpy as np
img1 = cv2.imread('messi5.jpg')
e1 = cv2.getTickCount()for i inrange(5,49,2):
img1 = cv2.medianBlur(img1,i)
e2 = cv2.getTickCount()
t =(e2-e1)/cv2.getTickFrequency()print(t)
0.0002125430419413002
x =5# IPython提供了一个魔法指令%timeit来干这个,它运行代码若干次来得到准确结果,很适合用来测量单行代码。
%timeit y=x**2
289 ns ± 10.3 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)
%timeit y=x*x
45 ns ± 1.07 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)
z = np.uint8([5])
%timeit y=z*z
The slowest run took 11.67 times longer than the fastest. This could mean that an intermediate result is being cached.
3.1 µs ± 4.39 µs per loop (mean ± std. dev. of 7 runs, 1 loop each)
%timeit y=np.square(z)
414 ns ± 9.65 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)