Skip to content

Instantly share code, notes, and snippets.

@hgdeoro
Created January 25, 2012 05:26
Show Gist options
  • Save hgdeoro/1674908 to your computer and use it in GitHub Desktop.
Save hgdeoro/1674908 to your computer and use it in GitHub Desktop.
Decorator for logging performance info
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
@hgdeoro
Copy link
Author

hgdeoro commented Jan 25, 2012

Haven't used timedelta.total_seconds() because doesn't work on old versions of python

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment