Created
January 26, 2012 22:03
-
-
Save omarish/1685386 to your computer and use it in GitHub Desktop.
Simple process timer in python.
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 datetime import datetime | |
import time | |
class timer: | |
def __enter__(self): | |
self.start = datetime.now() | |
return self | |
def __exit__(self, type, value, traceback): | |
self.end = datetime.now() | |
print "time: %s" % (self.end - self.start) | |
with timer() as t: | |
print "Hello, World!" | |
time.sleep(2) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment