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