Created
July 10, 2021 16:38
-
-
Save taross-f/1bbe4427f7c7c3ed03500d73f065c2c0 to your computer and use it in GitHub Desktop.
Timer decorator
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 time import time | |
import functools | |
class Timer(): | |
def __init__(self, func): | |
self._func = func | |
functools.update_wrapper(self, func) | |
def __call__(self, *args, **kwargs): | |
now = time() | |
print("-----------------------------------------------") | |
print(f"Start {self._func.__name__} {args=} {kwargs=}") | |
try: | |
self._func(*args, **kwargs) | |
finally: | |
print(f"Finished in {time() - now} {self._func.__name__} {args=} {kwargs=}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment