@contextmanager
def timer(log=None, message=None):
    if log is not None:
        log("{}...".format(message))

    info = {}
    t0 = time()
    yield info

    info['elapsed'] = time() - t0
    if log is not None:
        log("{} done in {:.3f} sec.".format(message, info['elapsed']))
dataset/ETHPy150Open ottogroup/palladium/palladium/util.py/timer/original