Skip to content

Commit 582289a

Browse files
committed
Add duration tracking and average time calculation to benchmark tests
1 parent c67bf91 commit 582289a

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

qwt/tests/test_curvebenchmark1.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ def __init__(self, max_n=1000000, parent=None, unattended=False, **kwargs):
142142
self.text = BMText(self)
143143
self.tabs.addTab(self.text, "Contents")
144144
self.resize(*self.SIZE)
145+
self.durations = []
145146

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

163-
time_str = "Elapsed time: %d ms" % ((time.time() - t0) * 1000)
164+
duration = (time.time() - t0) * 1000
165+
self.durations.append(duration)
166+
time_str = "Elapsed time: %d ms" % duration
164167
widget.text.setText(time_str)
165168
self.text.append("<br><i>%s:</i><br>%s" % (description, time_str))
166169
print("[%s] %s" % (utils.get_lib_versions(), time_str))

qwt/tests/test_loadtest.py

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010

1111
import time
1212

13+
import numpy as np
14+
1315
# Local imports
1416
from qwt.tests import test_curvebenchmark1 as cb
1517
from qwt.tests import utils
@@ -47,6 +49,9 @@ def run_benchmark(self, max_n, unattended, **kwargs):
4749
symtext,
4850
)
4951
self.process_iteration(title, description, widget, t0)
52+
print("")
53+
time_str = "Average elapsed time: %d ms" % np.mean(self.durations)
54+
print("[%s] %s" % (utils.get_lib_versions(), time_str))
5055

5156

5257
def test_loadtest():

0 commit comments

Comments
 (0)