Skip to content

Instantly share code, notes, and snippets.

@maniartech
Created November 10, 2012 14:43
Show Gist options
  • Save maniartech/4051292 to your computer and use it in GitHub Desktop.
Save maniartech/4051292 to your computer and use it in GitHub Desktop.
A python decorator that prints the function execution duration useful for bench-marking.
def benchmark(func):
"""
A decorator that prints the function execution duration useful for bench-marking.
"""
import time
def wrapper(*args, **kwargs):
t = time.clock()
res = func(*args, **kwargs)
print func.__name__, time.clock()-t
return res
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment