Created
November 10, 2023 17:34
-
-
Save adamghill/cc4427a6511790617a0e0bd927c734bf to your computer and use it in GitHub Desktop.
timeit 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
from contextlib import contextmanager | |
import time | |
@contextmanager | |
def timeit(): | |
""" | |
Decorator that prints out how long a function took to run. | |
""" | |
now = time.monotonic() | |
try: | |
yield | |
finally: | |
print(f"Function took {time.monotonic() - now}s.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment