Add docstrings for stopwatch class
@@ -42,11 +42,17 @@ def report_metric(name, data):
class Stopwatch(object):
+ """
+ Simple time measuring class.
+ """
def __init__(self):
self.timestamp = None
self.time = None
def start(self):
+ """
+ Start a time measurement
+ """
self.timestamp = time.time()
def lap(self):
@@ -56,15 +62,24 @@ class Stopwatch(object):
return cur_time - start_time
def stop(self):
+ """
+ Stop a running time measurement. returns the measured time
+ """
cur_time = time.time()
start_time = self.timestamp
self.time = cur_time - start_time
return self.time
def __enter__(self):
+ """
+ Start stopwatch when entering with-block.
+ """
self.start()
def __exit__(self, tpe, value, tb):
+ """
+ Stop stopwatch when exiting with-block.
+ """
self.stop()
def __str__(self):
