Skip to content

Instantly share code, notes, and snippets.

@adamghill
Created November 10, 2023 17:34
Show Gist options
  • Save adamghill/cc4427a6511790617a0e0bd927c734bf to your computer and use it in GitHub Desktop.
Save adamghill/cc4427a6511790617a0e0bd927c734bf to your computer and use it in GitHub Desktop.
timeit decorator
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