blob: ff3a4cfd697919bb60f00cfd88dcc9c126132aec (
plain) (
tree)
|
|
from __future__ import unicode_literals
import time
__all__ = (
'TimeIt',
)
class TimeIt(object):
"""
Context manager that times the duration of the code body.
The `duration` attribute will contain the execution time in seconds.
"""
def __init__(self):
self.duration = None
def __enter__(self):
self.start = time.time()
return self
def __exit__(self, *args):
self.end = time.time()
self.duration = self.end - self.start
|