Skip to content

Instantly share code, notes, and snippets.

@vlad-bezden
Last active August 7, 2018 18:49
Show Gist options
  • Save vlad-bezden/fd63ba037ed6c5f083a4f037b3674ddd to your computer and use it in GitHub Desktop.
Save vlad-bezden/fd63ba037ed6c5f083a4f037b3674ddd to your computer and use it in GitHub Desktop.
python timer contextmanager
from contextlib import contextmanager
import time
@contextmanager
def timer():
start = time.time()
yield
print(f'\N{greek capital letter delta}t \N{rightwards arrow} {time.time() - start:.2f}s')
@vlad-bezden
Copy link
Author

# usage example
with timer():
    time.sleep(1)
    
# output
# Δt → 1.00s

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment