from lldbtest import *
"""Stopwatch provides a simple utility to start/stop your stopwatch multiple
times. Each start/stop is equal to a lap, with its elapsed time accumulated
while measurment is in progress.
When you're ready to start from scratch for another round of measurements,
be sure to call the reset() method.
sw = Stopwatch()
for i in range(1000):
# Do some length operations...
# Get the average time.
avg_time = sw.avg()
# Reset the stopwatch as we are about to perform other kind of operations.
Context management protocol on entry to the body of the with statement.
def __exit__(self, type, value, tb):
Context management protocol on exit from the body of the with statement.
self.__laps__ = 0
self.__total_elapsed__ = 0.0
self.__start__ = None
self.__stop__ = None
self.__elapsed__ = 0.0
self.__nums__ = 
if self.__start__ is None:
self.__start__ = time.time()
raise Exception("start() already called, did you forget to stop() first?")
if self.__start__ is not None:
self.__stop__ = time.time()
elapsed = self.__stop__ - self.__start__
self.__total_elapsed__ += elapsed
self.__laps__ += 1
self.__start__ = None else:
raise Exception("stop() called without first start()?")
"""Gets the number of laps. One lap is equal to a start/stop action."""
"""Equal to total elapsed time divided by the number of laps."""
return self.__total_elapsed__ / self.__laps__
return "Avg: %f (Laps: %d, Total Elapsed Time: %f, min=%f, max=%f)" % (self.avg(),
Abstract base class for benchmark tests.
"""Fixture for unittest test case setup."""
self.stopwatch = Stopwatch()
"""Fixture for unittest test case teardown."""