Created
March 17, 2015 20:32
-
-
Save nickvandewiele/fd62c4bb67bb9ff84f43 to your computer and use it in GitHub Desktop.
timing decorator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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