diff options
author | Thiago Macieira <thiago.macieira@intel.com> | 2022-10-21 11:56:37 -0700 |
---|---|---|
committer | Thiago Macieira <thiago.macieira@intel.com> | 2022-11-09 02:18:44 -0700 |
commit | b5b00e77906af0ebc848d9244fab816bd1c9afcc (patch) | |
tree | 4bf3a3e48fb832010c1a8c66210ad96d79722273 | |
parent | 985b94215276eebf4acdd2625829d90a27213d64 (diff) |
QBenchlib: use QBenchmarkMeasurerBase::Measurement in QBenchmarkResult
Change-Id: I3c79b7e08fa346988dfefffd17202a818cde1d84
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | src/testlib/qbenchmark.cpp | 4 | ||||
-rw-r--r-- | src/testlib/qbenchmark_p.h | 12 | ||||
-rw-r--r-- | src/testlib/qcsvbenchmarklogger.cpp | 5 | ||||
-rw-r--r-- | src/testlib/qplaintestlogger.cpp | 9 | ||||
-rw-r--r-- | src/testlib/qtestcase.cpp | 16 | ||||
-rw-r--r-- | src/testlib/qxmltestlogger.cpp | 4 |
6 files changed, 22 insertions, 28 deletions
diff --git a/src/testlib/qbenchmark.cpp b/src/testlib/qbenchmark.cpp index e2df24ae7d..48f22aec34 100644 --- a/src/testlib/qbenchmark.cpp +++ b/src/testlib/qbenchmark.cpp @@ -124,8 +124,8 @@ void QBenchmarkTestMethodData::setResult(QBenchmarkMeasurerBase::Measurement m, else iterationCount *= 2; - this->result = QBenchmarkResult( - QBenchmarkGlobalData::current->context, m.value, iterationCount, m.metric, setByMacro); + this->result = QBenchmarkResult(QBenchmarkGlobalData::current->context, m, + iterationCount, setByMacro); } /*! diff --git a/src/testlib/qbenchmark_p.h b/src/testlib/qbenchmark_p.h index 50fb8ca880..dca3de8441 100644 --- a/src/testlib/qbenchmark_p.h +++ b/src/testlib/qbenchmark_p.h @@ -61,28 +61,26 @@ class QBenchmarkResult { public: QBenchmarkContext context; - qreal value = -1; + QBenchmarkMeasurerBase::Measurement measurement = { -1, QTest::FramesPerSecond }; int iterations = -1; - QTest::QBenchmarkMetric metric = QTest::FramesPerSecond; bool setByMacro = true; bool valid = false; QBenchmarkResult() = default; QBenchmarkResult( - const QBenchmarkContext &context, const qreal value, const int iterations, - QTest::QBenchmarkMetric metric, bool setByMacro) + const QBenchmarkContext &context, QBenchmarkMeasurerBase::Measurement m, + const int iterations, bool setByMacro) : context(context) - , value(value) + , measurement(m) , iterations(iterations) - , metric(metric) , setByMacro(setByMacro) , valid(true) { } bool operator<(const QBenchmarkResult &other) const { - return (value / iterations) < (other.value / other.iterations); + return (measurement.value / iterations) < (other.measurement.value / other.iterations); } }; Q_DECLARE_TYPEINFO(QBenchmarkResult, Q_RELOCATABLE_TYPE); diff --git a/src/testlib/qcsvbenchmarklogger.cpp b/src/testlib/qcsvbenchmarklogger.cpp index 1514936a1d..d4de8f08b7 100644 --- a/src/testlib/qcsvbenchmarklogger.cpp +++ b/src/testlib/qcsvbenchmarklogger.cpp @@ -57,13 +57,14 @@ void QCsvBenchmarkLogger::addBenchmarkResult(const QBenchmarkResult &result) : ""; const char *filler = (tag[0] && gtag[0]) ? ":" : ""; - const char *metric = QTest::benchmarkMetricName(result.metric); + const char *metric = QTest::benchmarkMetricName(result.measurement.metric); char buf[1024]; // "function","[globaltag:]tag","metric",value_per_iteration,total,iterations qsnprintf(buf, sizeof(buf), "\"%s\",\"%s%s%s\",\"%s\",%.13g,%.13g,%u\n", fn, gtag, filler, tag, metric, - result.value / result.iterations, result.value, result.iterations); + result.measurement.value / result.iterations, + result.measurement.value, result.iterations); outputString(buf); } diff --git a/src/testlib/qplaintestlogger.cpp b/src/testlib/qplaintestlogger.cpp index dd5282cdb1..1d33d39e6e 100644 --- a/src/testlib/qplaintestlogger.cpp +++ b/src/testlib/qplaintestlogger.cpp @@ -265,11 +265,11 @@ void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result) char fill[1024]; qsnprintf(fill, sizeof(fill), fillFormat, ""); - const char * unitText = QTest::benchmarkMetricUnit(result.metric); + const char * unitText = QTest::benchmarkMetricUnit(result.measurement.metric); - qreal valuePerIteration = qreal(result.value) / qreal(result.iterations); + qreal valuePerIteration = qreal(result.measurement.value) / qreal(result.iterations); char resultBuffer[100] = ""; - QTest::formatResult(resultBuffer, 100, valuePerIteration, QTest::countSignificantDigits(result.value)); + QTest::formatResult(resultBuffer, 100, valuePerIteration, QTest::countSignificantDigits(result.measurement.value)); char buf2[1024]; qsnprintf(buf2, sizeof(buf2), "%s %s", resultBuffer, unitText); @@ -281,7 +281,8 @@ void QPlainTestLogger::printBenchmarkResult(const QBenchmarkResult &result) char buf3[1024]; Q_ASSERT(result.iterations > 0); - QTest::formatResult(resultBuffer, 100, result.value, QTest::countSignificantDigits(result.value)); + QTest::formatResult(resultBuffer, 100, result.measurement.value, + QTest::countSignificantDigits(result.measurement.value)); qsnprintf(buf3, sizeof(buf3), " (total: %s, iterations: %d)", resultBuffer, result.iterations); char buf[1024]; diff --git a/src/testlib/qtestcase.cpp b/src/testlib/qtestcase.cpp index 335b72f1fb..24581011c2 100644 --- a/src/testlib/qtestcase.cpp +++ b/src/testlib/qtestcase.cpp @@ -1097,15 +1097,6 @@ struct QTestDataSetter } }; -namespace { - -qreal addResult(qreal current, const QBenchmarkResult& r) -{ - return current + r.value; -} - -} - void TestMethods::invokeTestOnData(int index) const { /* Benchmarking: for each median iteration*/ @@ -1179,11 +1170,11 @@ void TestMethods::invokeTestOnData(int index) const if (i == -1) { QTestLog::info(qPrintable( QString::fromLatin1("warmup stage result : %1") - .arg(QBenchmarkTestMethodData::current->result.value)), nullptr, 0); + .arg(QBenchmarkTestMethodData::current->result.measurement.value)), nullptr, 0); } else { QTestLog::info(qPrintable( QString::fromLatin1("accumulation stage result: %1") - .arg(QBenchmarkTestMethodData::current->result.value)), nullptr, 0); + .arg(QBenchmarkTestMethodData::current->result.measurement.value)), nullptr, 0); } } } @@ -1192,6 +1183,9 @@ void TestMethods::invokeTestOnData(int index) const if (QBenchmarkGlobalData::current->minimumTotal == -1) { minimumTotalReached = true; } else { + auto addResult = [](qreal current, const QBenchmarkResult& r) { + return current + r.measurement.value; + }; const qreal total = std::accumulate(results.begin(), results.end(), 0.0, addResult); minimumTotalReached = (total >= QBenchmarkGlobalData::current->minimumTotal); } diff --git a/src/testlib/qxmltestlogger.cpp b/src/testlib/qxmltestlogger.cpp index ff4fff7c98..27da73ba52 100644 --- a/src/testlib/qxmltestlogger.cpp +++ b/src/testlib/qxmltestlogger.cpp @@ -255,14 +255,14 @@ void QXmlTestLogger::addBenchmarkResult(const QBenchmarkResult &result) QTestCharBuffer quotedMetric; QTestCharBuffer quotedTag; - if (xmlQuote("edMetric, benchmarkMetricName(result.metric)) + if (xmlQuote("edMetric, benchmarkMetricName(result.measurement.metric)) && xmlQuote("edTag, result.context.tag.toUtf8().constData())) { QTestCharBuffer buf; QTest::qt_asprintf(&buf, QTest::benchmarkResultFormatString(), quotedMetric.constData(), quotedTag.constData(), - result.value / double(result.iterations), + result.measurement.value / double(result.iterations), result.iterations); outputString(buf.constData()); } |