I am trying to measure cpu time of a small function that usually takes about 1500 microseconds. I sometimesget inaccurate or wide confidence interval. I would like to find best accurate way to benchmark the function in python 3.7. I would like to measure the function time + get the return values for other calculations.
I tried defualt_timer from timeit, see my code below.
from timeit import default_timer as timer times= # store the times for 100 runs,then get min,max,averages etc for i in range (100): t1= timer() x,y,z = apply_message(s,text) t2= timer() execution_time= (t2-t1) * 1000000 # convert it to microsecond times+=[execution_time]
I found sometimes the minimum 1300 and max 75000, big difference. In other cases they are close. What i want to see at least results that gives me 95 confidence interval less than 10% from average.