Skip to content

Instantly share code, notes, and snippets.

@mherrmann
mherrmann / timer.py
Last active December 15, 2015 16:22
Measure the time taken by some Python code
from collections import OrderedDict
from time import time
class Timer(object):
"""
Measure the time taken by some Python code, incl. its subtasks:
>>> with Timer('parent') as timer:
... sleep(0.5)
... with timer.child('child') as child: