-
-
Save alkasm/81d3153fd301e5e6be5b22d451405152 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 | |
import time | |
logger = logging.getLogger(__name__) | |
def timed(func): | |
"""This decoratorlogs 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( | |
"{} took {:03d} ms".format(func.__name__, int(1000 * (end - start))) | |
) | |
return result | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment