From 43bcdcfce3c24e6986af74d13833db1b97c0a644 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Sat, 15 Aug 2020 16:11:20 +0300 Subject: [PATCH] remove unused and redundant test module methods Signed-off-by: Ivailo Monev --- src/test/qbenchmark.cpp | 109 ++++++----------------------- src/test/qbenchmark_p.h | 14 ---- src/test/qbenchmarkevent.cpp | 11 --- src/test/qbenchmarkevent_p.h | 3 - src/test/qbenchmarkmeasurement.cpp | 20 ------ src/test/qbenchmarkmeasurement_p.h | 7 -- src/test/qbenchmarkvalgrind.cpp | 10 --- src/test/qbenchmarkvalgrind_p.h | 2 - 8 files changed, 20 insertions(+), 156 deletions(-) diff --git a/src/test/qbenchmark.cpp b/src/test/qbenchmark.cpp index 9fc9f3304..d3c988748 100644 --- a/src/test/qbenchmark.cpp +++ b/src/test/qbenchmark.cpp @@ -52,8 +52,7 @@ QBenchmarkGlobalData::QBenchmarkGlobalData() : measurer(0) , walltimeMinimum(-1) , iterationCount(-1) - , medianIterationCount(-1) - , createChart(false) + , medianIterationCount(1) , verboseOutput(false) , mode_(WallTime) { @@ -72,36 +71,25 @@ void QBenchmarkGlobalData::setMode(Mode mode) if (measurer) delete measurer; - measurer = createMeasurer(); -} -QBenchmarkMeasurerBase * QBenchmarkGlobalData::createMeasurer() -{ - QBenchmarkMeasurerBase *m = 0; - if (0) { + if (mode_ == EventCounter) { + measurer = new QBenchmarkEvent; #ifdef QTESTLIB_USE_VALGRIND } else if (mode_ == CallgrindChildProcess || mode_ == CallgrindParentProcess) { - m = new QBenchmarkCallgrindMeasurer; + measurer = new QBenchmarkCallgrindMeasurer; #endif #ifdef HAVE_TICK_COUNTER } else if (mode_ == TickCounter) { - m = new QBenchmarkTickMeasurer; + measurer = new QBenchmarkTickMeasurer; #endif - } else if (mode_ == EventCounter) { - m = new QBenchmarkEvent; } else { - m = new QBenchmarkTimeMeasurer; + measurer = new QBenchmarkTimeMeasurer; } - return m; } int QBenchmarkGlobalData::adjustMedianIterationCount() { - if (medianIterationCount != -1) { - return medianIterationCount; - } else { - return measurer->adjustMedianCount(1); - } + return medianIterationCount; } @@ -120,7 +108,12 @@ QBenchmarkTestMethodData::~QBenchmarkTestMethodData() void QBenchmarkTestMethodData::beginDataRun() { - iterationCount = adjustIterationCount(1); + // Let the -iterations option override the measurer. + if (QBenchmarkGlobalData::current->iterationCount != -1) { + iterationCount = QBenchmarkGlobalData::current->iterationCount; + } else { + iterationCount = 1; + } } void QBenchmarkTestMethodData::endDataRun() @@ -128,18 +121,6 @@ void QBenchmarkTestMethodData::endDataRun() } -int QBenchmarkTestMethodData::adjustIterationCount(int suggestion) -{ - // Let the -iterations option override the measurer. - if (QBenchmarkGlobalData::current->iterationCount != -1) { - iterationCount = QBenchmarkGlobalData::current->iterationCount; - } else { - iterationCount = QBenchmarkGlobalData::current->measurer->adjustIterationCount(suggestion); - } - - return iterationCount; -} - void QBenchmarkTestMethodData::setResult( qreal value, QTest::QBenchmarkMetric metric, bool setByMacro) { @@ -188,20 +169,23 @@ QTest::QBenchmarkIterationController::QBenchmarkIterationController(RunMode runM i = 0; if (runMode == RunOnce) QBenchmarkTestMethodData::current->runOnce = true; - QTest::beginBenchmarkMeasurement(); + QBenchmarkGlobalData::current->measurer->start(); + // the clock is ticking after the line above, don't add code here. } QTest::QBenchmarkIterationController::QBenchmarkIterationController() { i = 0; - QTest::beginBenchmarkMeasurement(); + QBenchmarkGlobalData::current->measurer->start(); + // the clock is ticking after the line above, don't add code here. } /*! \internal */ QTest::QBenchmarkIterationController::~QBenchmarkIterationController() { - const qreal result = QTest::endBenchmarkMeasurement(); + // the clock is ticking before the line below, don't add code here. + const qreal result = QBenchmarkGlobalData::current->measurer->stop(); QBenchmarkTestMethodData::current->setResult(result, QBenchmarkGlobalData::current->measurer->metricType()); } @@ -211,7 +195,7 @@ bool QTest::QBenchmarkIterationController::isDone() { if (QBenchmarkTestMethodData::current->runOnce) return i > 0; - return i >= QTest::iterationCount(); + return i >= QBenchmarkTestMethodData::current->iterationCount; } /*! \internal @@ -221,44 +205,6 @@ void QTest::QBenchmarkIterationController::next() ++i; } -/*! \internal -*/ -int QTest::iterationCount() -{ - return QBenchmarkTestMethodData::current->iterationCount; -} - -/*! \internal -*/ -void QTest::setIterationCountHint(int count) -{ - QBenchmarkTestMethodData::current->adjustIterationCount(count); -} - -/*! \internal -*/ -void QTest::setIterationCount(int count) -{ - QBenchmarkTestMethodData::current->iterationCount = count; - QBenchmarkTestMethodData::current->resultAccepted = true; -} - -/*! \internal -*/ -void QTest::beginBenchmarkMeasurement() -{ - QBenchmarkGlobalData::current->measurer->start(); - // the clock is ticking after the line above, don't add code here. -} - -/*! \internal -*/ -quint64 QTest::endBenchmarkMeasurement() -{ - // the clock is ticking before the line below, don't add code here. - return QBenchmarkGlobalData::current->measurer->stop(); -} - /*! Sets the benchmark result for this test function to \a result. @@ -281,19 +227,4 @@ void QTest::setBenchmarkResult(qreal result, QTest::QBenchmarkMetric metric) QBenchmarkTestMethodData::current->setResult(result, metric, false); } -template -Q_TYPENAME T::value_type qAverage(const T &container) -{ - Q_TYPENAME T::const_iterator it = container.constBegin(); - Q_TYPENAME T::const_iterator end = container.constEnd(); - Q_TYPENAME T::value_type acc = Q_TYPENAME T::value_type(); - int count = 0; - while (it != end) { - acc += *it; - ++it; - ++count; - } - return acc / count; -} - QT_END_NAMESPACE diff --git a/src/test/qbenchmark_p.h b/src/test/qbenchmark_p.h index 8a723208a..60fd6e9ff 100644 --- a/src/test/qbenchmark_p.h +++ b/src/test/qbenchmark_p.h @@ -123,7 +123,6 @@ public: enum Mode { WallTime, CallgrindParentProcess, CallgrindChildProcess, TickCounter, EventCounter }; void setMode(Mode mode); Mode mode() const { return mode_; } - QBenchmarkMeasurerBase *createMeasurer(); int adjustMedianIterationCount(); QBenchmarkMeasurerBase *measurer; @@ -131,7 +130,6 @@ public: int walltimeMinimum; int iterationCount; int medianIterationCount; - bool createChart; bool verboseOutput; QString callgrindOutFileBase; private: @@ -158,7 +156,6 @@ public: bool isBenchmark() const { return result.valid; } bool resultsAccepted() const { return resultAccepted; } - int adjustIterationCount(int suggestion); void setResult(qreal value, QTest::QBenchmarkMetric metric, bool setByMacro = true); QBenchmarkResult result; @@ -167,17 +164,6 @@ public: int iterationCount; }; -// low-level API: -namespace QTest -{ - int iterationCount(); - void setIterationCountHint(int count); - void setIterationCount(int count); - - Q_TEST_EXPORT void beginBenchmarkMeasurement(); - Q_TEST_EXPORT quint64 endBenchmarkMeasurement(); -} - QT_END_NAMESPACE #endif // QBENCHMARK_H diff --git a/src/test/qbenchmarkevent.cpp b/src/test/qbenchmarkevent.cpp index c7766452d..1da9d03eb 100644 --- a/src/test/qbenchmarkevent.cpp +++ b/src/test/qbenchmarkevent.cpp @@ -73,17 +73,6 @@ bool QBenchmarkEvent::isMeasurementAccepted(qint64 measurement) return true; } -int QBenchmarkEvent::adjustIterationCount(int suggestion) -{ - return suggestion; -} - -int QBenchmarkEvent::adjustMedianCount(int suggestion) -{ - Q_UNUSED(suggestion); - return 1; -} - QTest::QBenchmarkMetric QBenchmarkEvent::metricType() { return QTest::Events; diff --git a/src/test/qbenchmarkevent_p.h b/src/test/qbenchmarkevent_p.h index 97d05f13b..557a85fed 100644 --- a/src/test/qbenchmarkevent_p.h +++ b/src/test/qbenchmarkevent_p.h @@ -59,9 +59,6 @@ public: qint64 checkpoint(); qint64 stop(); bool isMeasurementAccepted(qint64 measurement); - int adjustIterationCount(int suggestion); - int adjustMedianCount(int suggestion); - bool repeatCount() { return 1; } QTest::QBenchmarkMetric metricType(); static bool eventCountingMechanism(void *message); static qint64 eventCounter; diff --git a/src/test/qbenchmarkmeasurement.cpp b/src/test/qbenchmarkmeasurement.cpp index 25851cbda..7d80884ec 100644 --- a/src/test/qbenchmarkmeasurement.cpp +++ b/src/test/qbenchmarkmeasurement.cpp @@ -62,21 +62,11 @@ bool QBenchmarkTimeMeasurer::isMeasurementAccepted(qint64 measurement) return (measurement > 50); } -int QBenchmarkTimeMeasurer::adjustIterationCount(int suggestion) -{ - return suggestion; -} - bool QBenchmarkTimeMeasurer::needsWarmupIteration() { return true; } -int QBenchmarkTimeMeasurer::adjustMedianCount(int) -{ - return 1; -} - QTest::QBenchmarkMetric QBenchmarkTimeMeasurer::metricType() { return QTest::WalltimeMilliseconds; @@ -106,16 +96,6 @@ bool QBenchmarkTickMeasurer::isMeasurementAccepted(qint64) return true; } -int QBenchmarkTickMeasurer::adjustIterationCount(int) -{ - return 1; -} - -int QBenchmarkTickMeasurer::adjustMedianCount(int) -{ - return 1; -} - bool QBenchmarkTickMeasurer::needsWarmupIteration() { return true; diff --git a/src/test/qbenchmarkmeasurement_p.h b/src/test/qbenchmarkmeasurement_p.h index a2cafcb19..3320aa35d 100644 --- a/src/test/qbenchmarkmeasurement_p.h +++ b/src/test/qbenchmarkmeasurement_p.h @@ -59,9 +59,6 @@ public: virtual qint64 checkpoint() = 0; virtual qint64 stop() = 0; virtual bool isMeasurementAccepted(qint64 measurement) = 0; - virtual int adjustIterationCount(int suggestion) = 0; - virtual int adjustMedianCount(int suggestion) = 0; - virtual bool repeatCount() { return 1; } virtual bool needsWarmupIteration() { return false; } virtual QTest::QBenchmarkMetric metricType() = 0; }; @@ -73,8 +70,6 @@ public: qint64 checkpoint(); qint64 stop(); bool isMeasurementAccepted(qint64 measurement); - int adjustIterationCount(int sugestion); - int adjustMedianCount(int suggestion); bool needsWarmupIteration(); QTest::QBenchmarkMetric metricType(); private: @@ -90,8 +85,6 @@ public: qint64 checkpoint(); qint64 stop(); bool isMeasurementAccepted(qint64 measurement); - int adjustIterationCount(int); - int adjustMedianCount(int suggestion); bool needsWarmupIteration(); QTest::QBenchmarkMetric metricType(); private: diff --git a/src/test/qbenchmarkvalgrind.cpp b/src/test/qbenchmarkvalgrind.cpp index b684bf083..f6ecebff7 100644 --- a/src/test/qbenchmarkvalgrind.cpp +++ b/src/test/qbenchmarkvalgrind.cpp @@ -234,16 +234,6 @@ bool QBenchmarkCallgrindMeasurer::isMeasurementAccepted(qint64 measurement) return true; } -int QBenchmarkCallgrindMeasurer::adjustIterationCount(int) -{ - return 1; -} - -int QBenchmarkCallgrindMeasurer::adjustMedianCount(int) -{ - return 1; -} - bool QBenchmarkCallgrindMeasurer::needsWarmupIteration() { return true; diff --git a/src/test/qbenchmarkvalgrind_p.h b/src/test/qbenchmarkvalgrind_p.h index 7bc906a99..83173c206 100644 --- a/src/test/qbenchmarkvalgrind_p.h +++ b/src/test/qbenchmarkvalgrind_p.h @@ -74,8 +74,6 @@ public: qint64 checkpoint(); qint64 stop(); bool isMeasurementAccepted(qint64 measurement); - int adjustIterationCount(int); - int adjustMedianCount(int); bool needsWarmupIteration(); QTest::QBenchmarkMetric metricType(); };