Created
June 22, 2015 16:21
-
-
Save crowsonkb/6a9508ad75eaf6d64e47 to your computer and use it in GitHub Desktop.
Timer 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
import time | |
class Timer: | |
def __init__(self, times): | |
self.times = times | |
self.start = None | |
def __enter__(self): | |
self.start = time.perf_counter() | |
return self.start | |
def __exit__(self, exc_type, exc_val, exc_tb): | |
finish = time.perf_counter() | |
self.times.append((self.start, finish)) | |
return False |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment