Skip to content

Instantly share code, notes, and snippets.

@nicelifeBS
Forked from bradmontgomery/LICENSE.txt
Created March 28, 2018 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nicelifeBS/fea17069a8ca1a5e17ca42a0d811bfd0 to your computer and use it in GitHub Desktop.
Save nicelifeBS/fea17069a8ca1a5e17ca42a0d811bfd0 to your computer and use it in GitHub Desktop.
A python decorator that logs execution time.
from functools import wraps
import logging
logger = logging.getLogger(__name__)
def timed(func):
"""This decorator prints the execution time for the decorated function."""
@wraps(func)
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
logger.debug("{} ran in {}s".format(func.__name__, round(end - start, 2)))
return result
return wrapper
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment