Created
January 25, 2012 05:26
-
-
Save hgdeoro/1674908 to your computer and use it in GitHub Desktop.
Decorator for logging performance info
This file contains hidden or 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
def log_performance(f): | |
@wraps(f) | |
def wrapper(*args, **kwds): | |
start = datetime.datetime.now() | |
ret = f(*args, **kwds) | |
end = datetime.datetime.now() | |
took = end - start | |
took = took.seconds + took.microseconds / 1000000.0 | |
logging.info("Call to %s() took: %f secs.", f.func_name, took) | |
return ret | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Haven't used timedelta.total_seconds() because doesn't work on old versions of python