Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
def timer(f):
Decorator to time the execution of a function
:param f: The function to be timed
:return: The time in seconds that it took for the function to execute
def timing_function():
ts = time()
te = time()
total_time = (te - ts)
print '\n', "Exceution time : ", total_time, '\n'
timing_function.__name__ = f.__name__
return timing_function
# Sample usage
def calc():
i = 0
while i < 1000:
i += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment