#!/usr/bin/env python
from timeit import default_timer

class Timer(object):
	def __init__(self, verbose=False):
		self.verbose = verbose
		self.timer = default_timer

	def __enter__(self):
		self.start = self.timer()
		return self

	def __exit__(self, *args):
		end = self.timer()
		self.elapsed_secs = end - self.start
		self.elapsed = self.elapsed_secs * 1000 # milisecs
		if self.verbose:
			print 'elapsed time: %f ms' % self.elapsed


