Last active
June 13, 2021 17:57
-
-
Save BasicWolf/8e4664e258e3553dcdf1 to your computer and use it in GitHub Desktop.
Python Tic-Toc decorator
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 functools import wraps | |
def measure(f): | |
import timeit | |
@wraps(f) | |
def wrapped_f(*args, **kwargs): | |
tic = timeit.default_timer() | |
ret = f(*args, **kwargs) | |
toc = timeit.default_timer() | |
print(f"TICTOC: {toc - tic}") | |
return ret | |
return wrapped_f |
Wow, I didn't even remember having this gist :D. Thanks @afshinbigboy. Yep, that closing parenthesis and also marking the wrapper function with @functools.wraps(f)
.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Just add a
)
at the end of line 7.