Created
June 7, 2023 20:13
-
-
Save overflowy/1ebe490636ec7a33be4569108b3e0299 to your computer and use it in GitHub Desktop.
Timer decorator
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
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