Skip to content

Instantly share code, notes, and snippets.

@omarish
Created January 26, 2012 22:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save omarish/1685386 to your computer and use it in GitHub Desktop.
Save omarish/1685386 to your computer and use it in GitHub Desktop.
Simple process timer in python.
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