-
-
Save nicelifeBS/fea17069a8ca1a5e17ca42a0d811bfd0 to your computer and use it in GitHub Desktop.
A python decorator that logs execution time.
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 | |
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