Skip to content

Instantly share code, notes, and snippets.

@taross-f
Created Jul 10, 2021
Embed
What would you like to do?
Timer decorator
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