-
-
Save carsongee/31221079718d048934685d2e1bf7e56d to your computer and use it in GitHub Desktop.
Quick & dirty python timer for copy/paste perf. Handy for quick measurements of functions with the decorator or blocks with the context manager
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 contextlib import contextmanager | |
from functools import wraps | |
from time import perf_counter | |
@contextmanager | |
def t(name: str): | |
start = perf_counter() | |
yield | |
print(f'TIMER {name}: {perf_counter() - start}') | |
def td(f): | |
@wraps(f) | |
def wrapper(*args, **kwargs): | |
with t(f'{f.__name__}'): | |
return f(*args, **kwargs) | |
return wrapper |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment