remove unused and redundant test module methods

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2020-08-15 16:11:20 +03:00
parent 27293db2e4
commit 43bcdcfce3
8 changed files with 20 additions and 156 deletions

View file

@ -52,8 +52,7 @@ QBenchmarkGlobalData::QBenchmarkGlobalData()
: measurer(0) : measurer(0)
, walltimeMinimum(-1) , walltimeMinimum(-1)
, iterationCount(-1) , iterationCount(-1)
, medianIterationCount(-1) , medianIterationCount(1)
, createChart(false)
, verboseOutput(false) , verboseOutput(false)
, mode_(WallTime) , mode_(WallTime)
{ {
@ -72,36 +71,25 @@ void QBenchmarkGlobalData::setMode(Mode mode)
if (measurer) if (measurer)
delete measurer; delete measurer;
measurer = createMeasurer();
}
QBenchmarkMeasurerBase * QBenchmarkGlobalData::createMeasurer() if (mode_ == EventCounter) {
{ measurer = new QBenchmarkEvent;
QBenchmarkMeasurerBase *m = 0;
if (0) {
#ifdef QTESTLIB_USE_VALGRIND #ifdef QTESTLIB_USE_VALGRIND
} else if (mode_ == CallgrindChildProcess || mode_ == CallgrindParentProcess) { } else if (mode_ == CallgrindChildProcess || mode_ == CallgrindParentProcess) {
m = new QBenchmarkCallgrindMeasurer; measurer = new QBenchmarkCallgrindMeasurer;
#endif #endif
#ifdef HAVE_TICK_COUNTER #ifdef HAVE_TICK_COUNTER
} else if (mode_ == TickCounter) { } else if (mode_ == TickCounter) {
m = new QBenchmarkTickMeasurer; measurer = new QBenchmarkTickMeasurer;
#endif #endif
} else if (mode_ == EventCounter) {
m = new QBenchmarkEvent;
} else { } else {
m = new QBenchmarkTimeMeasurer; measurer = new QBenchmarkTimeMeasurer;
} }
return m;
} }
int QBenchmarkGlobalData::adjustMedianIterationCount() int QBenchmarkGlobalData::adjustMedianIterationCount()
{ {
if (medianIterationCount != -1) { return medianIterationCount;
return medianIterationCount;
} else {
return measurer->adjustMedianCount(1);
}
} }
@ -120,7 +108,12 @@ QBenchmarkTestMethodData::~QBenchmarkTestMethodData()
void QBenchmarkTestMethodData::beginDataRun() 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() 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( void QBenchmarkTestMethodData::setResult(
qreal value, QTest::QBenchmarkMetric metric, bool setByMacro) qreal value, QTest::QBenchmarkMetric metric, bool setByMacro)
{ {
@ -188,20 +169,23 @@ QTest::QBenchmarkIterationController::QBenchmarkIterationController(RunMode runM
i = 0; i = 0;
if (runMode == RunOnce) if (runMode == RunOnce)
QBenchmarkTestMethodData::current->runOnce = true; 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() QTest::QBenchmarkIterationController::QBenchmarkIterationController()
{ {
i = 0; i = 0;
QTest::beginBenchmarkMeasurement(); QBenchmarkGlobalData::current->measurer->start();
// the clock is ticking after the line above, don't add code here.
} }
/*! \internal /*! \internal
*/ */
QTest::QBenchmarkIterationController::~QBenchmarkIterationController() 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()); QBenchmarkTestMethodData::current->setResult(result, QBenchmarkGlobalData::current->measurer->metricType());
} }
@ -211,7 +195,7 @@ bool QTest::QBenchmarkIterationController::isDone()
{ {
if (QBenchmarkTestMethodData::current->runOnce) if (QBenchmarkTestMethodData::current->runOnce)
return i > 0; return i > 0;
return i >= QTest::iterationCount(); return i >= QBenchmarkTestMethodData::current->iterationCount;
} }
/*! \internal /*! \internal
@ -221,44 +205,6 @@ void QTest::QBenchmarkIterationController::next()
++i; ++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. 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); QBenchmarkTestMethodData::current->setResult(result, metric, false);
} }
template <typename T>
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 QT_END_NAMESPACE

View file

@ -123,7 +123,6 @@ public:
enum Mode { WallTime, CallgrindParentProcess, CallgrindChildProcess, TickCounter, EventCounter }; enum Mode { WallTime, CallgrindParentProcess, CallgrindChildProcess, TickCounter, EventCounter };
void setMode(Mode mode); void setMode(Mode mode);
Mode mode() const { return mode_; } Mode mode() const { return mode_; }
QBenchmarkMeasurerBase *createMeasurer();
int adjustMedianIterationCount(); int adjustMedianIterationCount();
QBenchmarkMeasurerBase *measurer; QBenchmarkMeasurerBase *measurer;
@ -131,7 +130,6 @@ public:
int walltimeMinimum; int walltimeMinimum;
int iterationCount; int iterationCount;
int medianIterationCount; int medianIterationCount;
bool createChart;
bool verboseOutput; bool verboseOutput;
QString callgrindOutFileBase; QString callgrindOutFileBase;
private: private:
@ -158,7 +156,6 @@ public:
bool isBenchmark() const { return result.valid; } bool isBenchmark() const { return result.valid; }
bool resultsAccepted() const { return resultAccepted; } bool resultsAccepted() const { return resultAccepted; }
int adjustIterationCount(int suggestion);
void setResult(qreal value, QTest::QBenchmarkMetric metric, bool setByMacro = true); void setResult(qreal value, QTest::QBenchmarkMetric metric, bool setByMacro = true);
QBenchmarkResult result; QBenchmarkResult result;
@ -167,17 +164,6 @@ public:
int iterationCount; 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 QT_END_NAMESPACE
#endif // QBENCHMARK_H #endif // QBENCHMARK_H

View file

@ -73,17 +73,6 @@ bool QBenchmarkEvent::isMeasurementAccepted(qint64 measurement)
return true; return true;
} }
int QBenchmarkEvent::adjustIterationCount(int suggestion)
{
return suggestion;
}
int QBenchmarkEvent::adjustMedianCount(int suggestion)
{
Q_UNUSED(suggestion);
return 1;
}
QTest::QBenchmarkMetric QBenchmarkEvent::metricType() QTest::QBenchmarkMetric QBenchmarkEvent::metricType()
{ {
return QTest::Events; return QTest::Events;

View file

@ -59,9 +59,6 @@ public:
qint64 checkpoint(); qint64 checkpoint();
qint64 stop(); qint64 stop();
bool isMeasurementAccepted(qint64 measurement); bool isMeasurementAccepted(qint64 measurement);
int adjustIterationCount(int suggestion);
int adjustMedianCount(int suggestion);
bool repeatCount() { return 1; }
QTest::QBenchmarkMetric metricType(); QTest::QBenchmarkMetric metricType();
static bool eventCountingMechanism(void *message); static bool eventCountingMechanism(void *message);
static qint64 eventCounter; static qint64 eventCounter;

View file

@ -62,21 +62,11 @@ bool QBenchmarkTimeMeasurer::isMeasurementAccepted(qint64 measurement)
return (measurement > 50); return (measurement > 50);
} }
int QBenchmarkTimeMeasurer::adjustIterationCount(int suggestion)
{
return suggestion;
}
bool QBenchmarkTimeMeasurer::needsWarmupIteration() bool QBenchmarkTimeMeasurer::needsWarmupIteration()
{ {
return true; return true;
} }
int QBenchmarkTimeMeasurer::adjustMedianCount(int)
{
return 1;
}
QTest::QBenchmarkMetric QBenchmarkTimeMeasurer::metricType() QTest::QBenchmarkMetric QBenchmarkTimeMeasurer::metricType()
{ {
return QTest::WalltimeMilliseconds; return QTest::WalltimeMilliseconds;
@ -106,16 +96,6 @@ bool QBenchmarkTickMeasurer::isMeasurementAccepted(qint64)
return true; return true;
} }
int QBenchmarkTickMeasurer::adjustIterationCount(int)
{
return 1;
}
int QBenchmarkTickMeasurer::adjustMedianCount(int)
{
return 1;
}
bool QBenchmarkTickMeasurer::needsWarmupIteration() bool QBenchmarkTickMeasurer::needsWarmupIteration()
{ {
return true; return true;

View file

@ -59,9 +59,6 @@ public:
virtual qint64 checkpoint() = 0; virtual qint64 checkpoint() = 0;
virtual qint64 stop() = 0; virtual qint64 stop() = 0;
virtual bool isMeasurementAccepted(qint64 measurement) = 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 bool needsWarmupIteration() { return false; }
virtual QTest::QBenchmarkMetric metricType() = 0; virtual QTest::QBenchmarkMetric metricType() = 0;
}; };
@ -73,8 +70,6 @@ public:
qint64 checkpoint(); qint64 checkpoint();
qint64 stop(); qint64 stop();
bool isMeasurementAccepted(qint64 measurement); bool isMeasurementAccepted(qint64 measurement);
int adjustIterationCount(int sugestion);
int adjustMedianCount(int suggestion);
bool needsWarmupIteration(); bool needsWarmupIteration();
QTest::QBenchmarkMetric metricType(); QTest::QBenchmarkMetric metricType();
private: private:
@ -90,8 +85,6 @@ public:
qint64 checkpoint(); qint64 checkpoint();
qint64 stop(); qint64 stop();
bool isMeasurementAccepted(qint64 measurement); bool isMeasurementAccepted(qint64 measurement);
int adjustIterationCount(int);
int adjustMedianCount(int suggestion);
bool needsWarmupIteration(); bool needsWarmupIteration();
QTest::QBenchmarkMetric metricType(); QTest::QBenchmarkMetric metricType();
private: private:

View file

@ -234,16 +234,6 @@ bool QBenchmarkCallgrindMeasurer::isMeasurementAccepted(qint64 measurement)
return true; return true;
} }
int QBenchmarkCallgrindMeasurer::adjustIterationCount(int)
{
return 1;
}
int QBenchmarkCallgrindMeasurer::adjustMedianCount(int)
{
return 1;
}
bool QBenchmarkCallgrindMeasurer::needsWarmupIteration() bool QBenchmarkCallgrindMeasurer::needsWarmupIteration()
{ {
return true; return true;

View file

@ -74,8 +74,6 @@ public:
qint64 checkpoint(); qint64 checkpoint();
qint64 stop(); qint64 stop();
bool isMeasurementAccepted(qint64 measurement); bool isMeasurementAccepted(qint64 measurement);
int adjustIterationCount(int);
int adjustMedianCount(int);
bool needsWarmupIteration(); bool needsWarmupIteration();
QTest::QBenchmarkMetric metricType(); QTest::QBenchmarkMetric metricType();
}; };