Skip to content

Instantly share code, notes, and snippets.

@tianhuil
tianhuil / Timer.py
Last active December 30, 2015 12:29
Python's timer module only takes statements as strings. Here's a timer class that you can use with a "with" statement to time even0 multi-line statements.
import datetime
class Timer:
def __init__(self, string=None):
self.string = string
def __enter__(self):
self.t1 = datetime.datetime.now()
def __exit__(self, exc_type, exc_value, traceback):