Files
derek.holloway 7502bf64a4
CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
Flatten subprojects into a single base monorepo
2026-09-02 16:34:47 -07:00

121 lines
3.4 KiB
Python

# System modules
import time
# Third-party modules
# LLDB modules
from .lldbtest import *
class Stopwatch(object):
"""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 measurement is in progress.
When you're ready to start from scratch for another round of measurements,
be sure to call the reset() method.
For example,
sw = Stopwatch()
for i in range(1000):
with sw:
# 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.
sw.reset()
...
"""
#############################################################
#
# Context manager interfaces to support the 'with' statement.
#
#############################################################
def __enter__(self):
"""
Context management protocol on entry to the body of the with statement.
"""
return self.start()
def __exit__(self, type, value, tb):
"""
Context management protocol on exit from the body of the with statement.
"""
self.stop()
def reset(self):
self.__laps__ = 0
self.__total_elapsed__ = 0.0
self.__start__ = None
self.__stop__ = None
self.__elapsed__ = 0.0
self.__nums__ = []
def __init__(self):
self.reset()
def start(self):
if self.__start__ is None:
self.__start__ = time.time()
else:
raise Exception("start() already called, did you forget to stop() first?")
# Return self to facilitate the context manager __enter__ protocol.
return self
def stop(self):
if self.__start__ is not None:
self.__stop__ = time.time()
elapsed = self.__stop__ - self.__start__
self.__total_elapsed__ += elapsed
self.__laps__ += 1
self.__nums__.append(elapsed)
self.__start__ = None # Reset __start__ to be None again.
else:
raise Exception("stop() called without first start()?")
def laps(self):
"""Gets the number of laps. One lap is equal to a start/stop action."""
return self.__laps__
def avg(self):
"""Equal to total elapsed time divided by the number of laps."""
return self.__total_elapsed__ / self.__laps__
# def sigma(self):
# """Return the standard deviation of the available samples."""
# if self.__laps__ <= 0:
# return None
# return numpy.std(self.__nums__)
def __str__(self):
return "Avg: %f (Laps: %d, Total Elapsed Time: %f, min=%f, max=%f)" % (
self.avg(),
self.__laps__,
self.__total_elapsed__,
min(self.__nums__),
max(self.__nums__),
)
class BenchBase(TestBase):
"""
Abstract base class for benchmark tests.
"""
def setUp(self):
"""Fixture for unittest test case setup."""
super(BenchBase, self).setUp()
# TestBase.setUp(self)
self.stopwatch = Stopwatch()
def tearDown(self):
"""Fixture for unittest test case teardown."""
super(BenchBase, self).tearDown()
# TestBase.tearDown(self)
del self.stopwatch