Last active
April 23, 2019 19:38
-
-
Save DahlitzFlorian/5e2ff136af9c43b1f8036b79d135d340 to your computer and use it in GitHub Desktop.
Article: How To Create Your Own Timing Context Manager
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 contextlib import contextmanager | |
from time import time | |
@contextmanager | |
def timing(description: str) -> None: | |
start = time() | |
yield | |
ellapsed_time = time() - start | |
print(f"{description}: {ellapsed_time}") | |
with timing("List Comprehension Example"): | |
s = [x for x in range(10_000_000)] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment