Skip to content

Instantly share code, notes, and snippets.

@nickvandewiele
Created March 17, 2015 20:32
Show Gist options
  • Save nickvandewiele/fd62c4bb67bb9ff84f43 to your computer and use it in GitHub Desktop.
Save nickvandewiele/fd62c4bb67bb9ff84f43 to your computer and use it in GitHub Desktop.
timing decorator
from functools import wraps
#From High Performance Python
def timefn(fn):
@wraps(fn)
def measure_time(*args, **kwargs):
t1 = time.time()
result = fn(*args, **kwargs)
t2 = time.time()
print ("@timefn:" + fn.func_name + " took " + str(t2 - t1) + " seconds")
return result
return measure_time
@timefn
def calculate():
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment