Skip to content

Instantly share code, notes, and snippets.

@overflowy
Created June 7, 2023 20:13
Show Gist options
  • Save overflowy/1ebe490636ec7a33be4569108b3e0299 to your computer and use it in GitHub Desktop.
Save overflowy/1ebe490636ec7a33be4569108b3e0299 to your computer and use it in GitHub Desktop.
Timer decorator
import functools
import time
def timer(func):
@functools.wraps(func)
def wrapper_timer(*args, **kwargs):
tic = time.perf_counter()
value = func(*args, **kwargs)
toc = time.perf_counter()
elapsed_time = toc - tic
print(f"{func.__class__}.{func.__name__}: {elapsed_time:0.5f} seconds")
return value
return wrapper_timer
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment