Skip to content

Commit

Permalink
Add duration tracking and average time calculation to benchmark tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PierreRaybaut committed Dec 24, 2024
1 parent c67bf91 commit 582289a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
5 changes: 4 additions & 1 deletion qwt/tests/test_curvebenchmark1.py
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ def __init__(self, max_n=1000000, parent=None, unattended=False, **kwargs):
self.text = BMText(self)
self.tabs.addTab(self.text, "Contents")
self.resize(*self.SIZE)
self.durations = []

# Force window to show up and refresh (for test purpose only)
self.show()
Expand All @@ -160,7 +161,9 @@ def process_iteration(self, title, description, widget, t0):
# Force widget to refresh (for test purpose only)
QApplication.processEvents()

time_str = "Elapsed time: %d ms" % ((time.time() - t0) * 1000)
duration = (time.time() - t0) * 1000
self.durations.append(duration)
time_str = "Elapsed time: %d ms" % duration
widget.text.setText(time_str)
self.text.append("<br><i>%s:</i><br>%s" % (description, time_str))
print("[%s] %s" % (utils.get_lib_versions(), time_str))
Expand Down
5 changes: 5 additions & 0 deletions qwt/tests/test_loadtest.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

import time

import numpy as np

# Local imports
from qwt.tests import test_curvebenchmark1 as cb
from qwt.tests import utils
Expand Down Expand Up @@ -47,6 +49,9 @@ def run_benchmark(self, max_n, unattended, **kwargs):
symtext,
)
self.process_iteration(title, description, widget, t0)
print("")
time_str = "Average elapsed time: %d ms" % np.mean(self.durations)
print("[%s] %s" % (utils.get_lib_versions(), time_str))


def test_loadtest():
Expand Down

0 comments on commit 582289a

Please sign in to comment.