Skip to content

Instantly share code, notes, and snippets.

@taross-f
Created July 10, 2021 16:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save taross-f/1bbe4427f7c7c3ed03500d73f065c2c0 to your computer and use it in GitHub Desktop.
Save taross-f/1bbe4427f7c7c3ed03500d73f065c2c0 to your computer and use it in GitHub Desktop.
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