# -*- coding: utf-8 -*-

# Simple timer to time a block of code, for optimization debugging
# use like:
#   with nilmdb.Timer("flush"):
#       foo.flush()

import contextlib
import time

@contextlib.contextmanager
def Timer(name = None):
    start = time.time()
    yield
    elapsed = int((time.time() - start) * 1000)
    print (name or 'elapsed') + ": " + str(elapsed) + " ms"
