Created
July 6, 2020 21:01
-
-
Save ahmed4end/b1dbd423fbd75c59ee740b966be81414 to your computer and use it in GitHub Desktop.
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 | |
from timeit import default_timer | |
import time | |
@contextmanager | |
def elapsed_timer(): | |
start = default_timer() | |
elapser = lambda: default_timer() - start | |
yield lambda: elapser() | |
end = default_timer() | |
elapser = lambda: end-start | |
with elapsed_timer() as elapsed: | |
for i in range(10): | |
# CODE HERE | |
pass | |
print("{:.8f}".format(float(elapsed()))) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment