summaryrefslogtreecommitdiffstats
path: root/src/testlib/qbenchmark.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@intel.com>2022-10-21 12:39:37 -0700
committerThiago Macieira <thiago.macieira@intel.com>2022-11-09 02:18:45 -0700
commit4731baf6d3a18857e86cc16de000bc42e84bf6de (patch)
treec81e80bbe29a995952b16ee284777ed33884b3ca /src/testlib/qbenchmark.cpp
parentb5b00e77906af0ebc848d9244fab816bd1c9afcc (diff)
QBenchlib: add support for a measurer reporting multiple results
Implemented for the Linux Perf measurer, with four measurements by default. RESULT : tst_MyClass::QString_toInt(): 149.574444 CPU cycles per iteration (total: 149,574,445, iterations: 1000000) RESULT : tst_MyClass::QString_toInt(): 620.000181 instructions per iteration (total: 620,000,182, iterations: 1000000) RESULT : tst_MyClass::QString_toInt(): 131.000046 branch instructions per iteration (total: 131,000,047, iterations: 1000000) RESULT : tst_MyClass::QString_toInt(): 32.118771 nsecs per iteration (total: 32,118,771, iterations: 1000000) Change-Id: I3c79b7e08fa346988dfefffd17202cda3df8431b Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src/testlib/qbenchmark.cpp')
-rw-r--r--src/testlib/qbenchmark.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/src/testlib/qbenchmark.cpp b/src/testlib/qbenchmark.cpp
index 48f22aec34..4a8bd72ee9 100644
--- a/src/testlib/qbenchmark.cpp
+++ b/src/testlib/qbenchmark.cpp
@@ -96,10 +96,13 @@ int QBenchmarkTestMethodData::adjustIterationCount(int suggestion)
return iterationCount;
}
-void QBenchmarkTestMethodData::setResult(QBenchmarkMeasurerBase::Measurement m,
- bool setByMacro)
+void QBenchmarkTestMethodData::setResults(const QList<QBenchmarkMeasurerBase::Measurement> &list,
+ bool setByMacro)
{
bool accepted = false;
+ QBenchmarkMeasurerBase::Measurement firstMeasurement = {};
+ if (!list.isEmpty())
+ firstMeasurement = list.constFirst();
// Always accept the result if the iteration count has been
// specified on the command line with -iterations.
@@ -114,9 +117,9 @@ void QBenchmarkTestMethodData::setResult(QBenchmarkMeasurerBase::Measurement m,
// Test the result directly without calling the measurer if the minimum time
// has been specified on the command line with -minimumvalue.
else if (QBenchmarkGlobalData::current->walltimeMinimum != -1)
- accepted = (m.value > QBenchmarkGlobalData::current->walltimeMinimum);
+ accepted = (firstMeasurement.value > QBenchmarkGlobalData::current->walltimeMinimum);
else
- accepted = QBenchmarkGlobalData::current->measurer->isMeasurementAccepted(m);
+ accepted = QBenchmarkGlobalData::current->measurer->isMeasurementAccepted(firstMeasurement);
// Accept the result or double the number of iterations.
if (accepted)
@@ -124,8 +127,10 @@ void QBenchmarkTestMethodData::setResult(QBenchmarkMeasurerBase::Measurement m,
else
iterationCount *= 2;
- this->result = QBenchmarkResult(QBenchmarkGlobalData::current->context, m,
- iterationCount, setByMacro);
+ valid = true;
+ results.reserve(list.size());
+ for (auto m : list)
+ results.emplaceBack(QBenchmarkGlobalData::current->context, m, iterationCount, setByMacro);
}
/*!
@@ -157,8 +162,7 @@ QTest::QBenchmarkIterationController::QBenchmarkIterationController()
*/
QTest::QBenchmarkIterationController::~QBenchmarkIterationController()
{
- QBenchmarkMeasurerBase::Measurement measurement = QTest::endBenchmarkMeasurement();
- QBenchmarkTestMethodData::current->setResult(measurement);
+ QBenchmarkTestMethodData::current->setResults(QTest::endBenchmarkMeasurement());
}
/*! \internal
@@ -209,7 +213,7 @@ void QTest::beginBenchmarkMeasurement()
/*! \internal
*/
-QBenchmarkMeasurerBase::Measurement QTest::endBenchmarkMeasurement()
+QList<QBenchmarkMeasurerBase::Measurement> QTest::endBenchmarkMeasurement()
{
// the clock is ticking before the line below, don't add code here.
return QBenchmarkGlobalData::current->measurer->stop();