Skip to content

Instantly share code, notes, and snippets.

@JamesHovious
Last active August 29, 2015 14:05
Show Gist options
  • Select an option

  • Save JamesHovious/fb22f2b70c48aa674c5d to your computer and use it in GitHub Desktop.

Select an option

Save JamesHovious/fb22f2b70c48aa674c5d to your computer and use it in GitHub Desktop.
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()
f()
te = time()
total_time = (te - ts)
print '\n', "Exceution time : ", total_time, '\n'
timing_function.__name__ = f.__name__
return timing_function
# Sample usage
@timer
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