def test(): c=0 for i in range(100): c=i-c return c print(test()) %timeit test() from timeit import Timer, timeit, repeat print(__name__) TimeIt = timeit("test()", setup="from __main__ import test", number=100000) Repeat = repeat("test()", setup="from __main__ import test", repeat=3, number=100000) print(TimeIt) print(Repeat, min(Repeat)) from numpy import random, sqrt func_list=[] def decorate(func): """This function populates the func_list with lists of function names and the functions themselves. The benifit of this is that is allow you to execute the functions just be itterating over them in a loop. Aside from populating the func_list this decorator has no affect on the function's behaviour.*""" global func_list func_list += [[func.__name__, func]] return func @decorate def add(data): result=0 for i, j in [line.split(',') for line in data]: result+= float(i)+float(j) return result @decorate def mult(data): result=0 for i, j in [line.split(',') for line in data]: result= result+float(i)*float(j) return result @decorate def dist(data): result=0 for i, j in [line.split(',') for line in data]: result= result+float(i)**2+float(j)**2 return sqrt(result) def pick2(a,b): #This is used to validate the passing of multiple variables to the Repeat_time function return a+b list_size = (412,2) #sample data size numbers = random.random_sample(size=list_size) larger_data_text = '' for x,y in numbers: larger_data_text += "{:.1f}, {:.1f}\n".format(x,y) larger_data_text = larger_data_text[:-1] larger_data = larger_data_text.splitlines() print(larger_data[0:10]+['...']) #Print the first 10 elements to see is the format is right. #global data #not sure if this is needed data = list(larger_data) print(add(data)) print(mult(data)) print(dist(data)) from IPython.core.display import HTML from TimeIt_Func import testing HTML(testing(func_list, data)) %timeit add(data) %timeit mult(data) %timeit dist(data) for func in func_list: #Copied from Liso77's notebook with only minor modification print(func[0]) %timeit func[1](data) print('\n') from TimeIt_Func import Repeat_time print(Repeat_time('add',"data")) print(Repeat_time('pick2',"1, 2")) from TimeIt_Func import time_func print(time_func("add","data",", data",1000))