Skip to content

Instantly share code, notes, and snippets.

@billyshambrook
Created March 30, 2015 16:58
Show Gist options
  • Save billyshambrook/6ffdffb67aad25e41ee6 to your computer and use it in GitHub Desktop.
Save billyshambrook/6ffdffb67aad25e41ee6 to your computer and use it in GitHub Desktop.
Context statement timer
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