I wanted to find the amount of time taken for a module/function to execute. I have used two methods mentioned below, but the time taken in each case is not same for the same funtion. why?
import time
from timeit import default_timer as timer
start=timer()
ret,thresh1 = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
end=timer()
print(Time Taken by Binary Thresh1 = {}".format(end-start))
e1=cv2.getTickCount()
ret,thresh1 = cv2.threshold(gray,127,255,cv2.THRESH_BINARY)
e2=cv2.getTickCount()
t=(e2-e1)/cv2.getTickFrequency()
print("Time Taken by Binary Thresh2 = {}".format(t))
Output
Time Taken by Binary Thresh1 = 0.00017630465444318233 Time Taken by Binary Thresh2 = 3.005609493620777e-05
Kindly let me what is the reason , or anything wrong in the code?