Skip to content

Instantly share code, notes, and snippets.

@BasicWolf
Last active June 13, 2021 17:57
Show Gist options
  • Save BasicWolf/8e4664e258e3553dcdf1 to your computer and use it in GitHub Desktop.
Save BasicWolf/8e4664e258e3553dcdf1 to your computer and use it in GitHub Desktop.
Python Tic-Toc decorator
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
@afshinbigboy
Copy link

Just add a ) at the end of line 7.

@BasicWolf
Copy link
Author

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