Created
March 30, 2015 16:58
-
-
Save billyshambrook/6ffdffb67aad25e41ee6 to your computer and use it in GitHub Desktop.
Context statement timer
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
import time | |
class Timer(object): | |
def __enter__(self): | |
self.start = time.clock() | |
return self | |
def __exit__(self, *args): | |
self.end = time.clock() | |
self.interval = self.end - self.start | |
with Timer() as t: | |
time.sleep(5) | |
print t.interval |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment