Skip to content

Instantly share code, notes, and snippets.

@crowsonkb
Created March 9, 2015 00:44
Show Gist options
  • Save crowsonkb/d6da7951635ecaed2839 to your computer and use it in GitHub Desktop.
Save crowsonkb/d6da7951635ecaed2839 to your computer and use it in GitHub Desktop.
class Timer:
def __enter__(self):
self.__interval = None
self.__start = time.perf_counter()
return self
def __exit__(self, *args):
self.__end = time.perf_counter()
self.__interval = self.__end - self.__start
print(self.__interval, file=sys.stderr)
def __call__(self):
return self.__interval
def __str__(self):
return str(self.__interval)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment