QtTest: don't hold QBenchmarkResults in QList

QBenchmarkResult is larger than a void*, so holding them in a QList is
needlessly inefficient. Worse, the code could come to depend on the
fragile property of (inefficient) QLists that references to elements
therein never are invalidated.

Also saves ~1.2KiB of text size on GCC 4.9 optimized C++11 AMD64
Linux builds.

Change-Id: I0c99e591bb9b4405aa1bb78ec095dcaf9277993f
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2014-08-17 20:44:39 +02:00
parent 3045ac99f2
commit e475017753
2 changed files with 5 additions and 3 deletions

View File

@ -91,6 +91,7 @@ struct QBenchmarkContext
QBenchmarkContext() : checkpointIndex(-1) {}
};
Q_DECLARE_TYPEINFO(QBenchmarkContext, Q_MOVABLE_TYPE);
class QBenchmarkResult
{
@ -126,6 +127,7 @@ public:
return (value / iterations) < (other.value / other.iterations);
}
};
Q_DECLARE_TYPEINFO(QBenchmarkResult, Q_MOVABLE_TYPE);
/*
The QBenchmarkGlobalData class stores global benchmark-related data.

View File

@ -1925,7 +1925,7 @@ Q_TESTLIB_EXPORT void qtest_qParseArgs(int argc, char *argv[], bool qml)
QTestLog::addLogger(logFormat, logFilename);
}
QBenchmarkResult qMedian(const QList<QBenchmarkResult> &container)
QBenchmarkResult qMedian(const QVector<QBenchmarkResult> &container)
{
const int count = container.count();
if (count == 0)
@ -1934,7 +1934,7 @@ QBenchmarkResult qMedian(const QList<QBenchmarkResult> &container)
if (count == 1)
return container.front();
QList<QBenchmarkResult> containerCopy = container;
QVector<QBenchmarkResult> containerCopy = container;
std::sort(containerCopy.begin(), containerCopy.end());
const int middle = count / 2;
@ -1971,7 +1971,7 @@ static void qInvokeTestMethodDataEntry(char *slot)
bool isBenchmark = false;
int i = (QBenchmarkGlobalData::current->measurer->needsWarmupIteration()) ? -1 : 0;
QList<QBenchmarkResult> results;
QVector<QBenchmarkResult> results;
bool minimumTotalReached = false;
do {
QBenchmarkTestMethodData::current->beginDataRun();