Use QList instead of QVector in benchmarks tests
Task-number: QTBUG-84469 Change-Id: Id61d6036067da0bcd0811b1b97df5f1334007b7e Reviewed-by: Lars Knoll <lars.knoll@qt.io>
This commit is contained in:
parent
d1612610e6
commit
74dc89de3e
@ -32,7 +32,7 @@
|
||||
#include <QDataStream>
|
||||
#include <QTcpSocket>
|
||||
#include <QImage>
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QPointer>
|
||||
#include <QStringList>
|
||||
@ -120,8 +120,7 @@ QDataStream & operator>> (QDataStream &stream, ImageItem& ii);
|
||||
|
||||
Q_DECLARE_METATYPE(ImageItem);
|
||||
|
||||
typedef QVector<ImageItem> ImageItemList;
|
||||
|
||||
typedef QList<ImageItem> ImageItemList;
|
||||
|
||||
class BaselineProtocol
|
||||
{
|
||||
|
@ -294,7 +294,7 @@ void tst_QMutex::contendedNative()
|
||||
NativeMutexInitialize(&mutex1);
|
||||
NativeMutexInitialize(&mutex2);
|
||||
|
||||
QVector<NativeMutexThread *> threads(threadCount);
|
||||
QList<NativeMutexThread *> threads(threadCount);
|
||||
for (int i = 0; i < threads.count(); ++i) {
|
||||
threads[i] = new NativeMutexThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes);
|
||||
threads[i]->start();
|
||||
@ -361,7 +361,7 @@ void tst_QMutex::contendedQMutex()
|
||||
|
||||
QMutex mutex1, mutex2;
|
||||
|
||||
QVector<QMutexThread *> threads(threadCount);
|
||||
QList<QMutexThread *> threads(threadCount);
|
||||
for (int i = 0; i < threads.count(); ++i) {
|
||||
threads[i] = new QMutexThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes);
|
||||
threads[i]->start();
|
||||
@ -423,7 +423,7 @@ void tst_QMutex::contendedQMutexLocker()
|
||||
|
||||
QMutex mutex1, mutex2;
|
||||
|
||||
QVector<QMutexLockerThread *> threads(threadCount);
|
||||
QList<QMutexLockerThread *> threads(threadCount);
|
||||
for (int i = 0; i < threads.count(); ++i) {
|
||||
threads[i] = new QMutexLockerThread(&mutex1, &mutex2, iterations, msleepDuration, use2mutexes);
|
||||
threads[i]->start();
|
||||
|
@ -28,7 +28,7 @@
|
||||
|
||||
#include <QDate>
|
||||
#include <QTest>
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
|
||||
class tst_QDate : public QObject
|
||||
{
|
||||
@ -41,8 +41,8 @@ class tst_QDate : public QObject
|
||||
JULIAN_DAY_2020 = 2458850,
|
||||
};
|
||||
|
||||
static QVector<QDate> daily(qint64 start, qint64 end);
|
||||
static QVector<QDate> yearly(qint32 first, qint32 last);
|
||||
static QList<QDate> daily(qint64 start, qint64 end);
|
||||
static QList<QDate> yearly(qint32 first, qint32 last);
|
||||
|
||||
private Q_SLOTS:
|
||||
void create();
|
||||
@ -60,18 +60,18 @@ private Q_SLOTS:
|
||||
void addYears();
|
||||
};
|
||||
|
||||
QVector<QDate> tst_QDate::daily(qint64 start, qint64 end)
|
||||
QList<QDate> tst_QDate::daily(qint64 start, qint64 end)
|
||||
{
|
||||
QVector<QDate> list;
|
||||
QList<QDate> list;
|
||||
list.reserve(end - start);
|
||||
for (qint64 jd = start; jd < end; ++jd)
|
||||
list.append(QDate::fromJulianDay(jd));
|
||||
return list;
|
||||
}
|
||||
|
||||
QVector<QDate> tst_QDate::yearly(qint32 first, qint32 last)
|
||||
QList<QDate> tst_QDate::yearly(qint32 first, qint32 last)
|
||||
{
|
||||
QVector<QDate> list;
|
||||
QList<QDate> list;
|
||||
list.reserve(last + 1 - first);
|
||||
for (qint32 year = first; year <= last; ++year)
|
||||
list.append(QDate(year, 3, 21));
|
||||
|
@ -29,7 +29,7 @@
|
||||
#include <QDateTime>
|
||||
#include <QTimeZone>
|
||||
#include <QTest>
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
#include <qdebug.h>
|
||||
|
||||
class tst_QDateTime : public QObject
|
||||
@ -50,8 +50,8 @@ class tst_QDateTime : public QObject
|
||||
JULIAN_DAY_2060 = 2473460
|
||||
};
|
||||
|
||||
static QVector<QDateTime> daily(qint64 start, qint64 end);
|
||||
static QVector<QDateTime> norse(qint64 start, qint64 end);
|
||||
static QList<QDateTime> daily(qint64 start, qint64 end);
|
||||
static QList<QDateTime> norse(qint64 start, qint64 end);
|
||||
|
||||
private Q_SLOTS:
|
||||
void create();
|
||||
@ -102,19 +102,19 @@ private Q_SLOTS:
|
||||
void fromMSecsSinceEpochTz();
|
||||
};
|
||||
|
||||
QVector<QDateTime> tst_QDateTime::daily(qint64 start, qint64 end)
|
||||
QList<QDateTime> tst_QDateTime::daily(qint64 start, qint64 end)
|
||||
{
|
||||
QVector<QDateTime> list;
|
||||
QList<QDateTime> list;
|
||||
list.reserve(end - start);
|
||||
for (int jd = start; jd < end; ++jd)
|
||||
list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0)));
|
||||
return list;
|
||||
}
|
||||
|
||||
QVector<QDateTime> tst_QDateTime::norse(qint64 start, qint64 end)
|
||||
QList<QDateTime> tst_QDateTime::norse(qint64 start, qint64 end)
|
||||
{
|
||||
const QTimeZone cet("Europe/Oslo");
|
||||
QVector<QDateTime> list;
|
||||
QList<QDateTime> list;
|
||||
list.reserve(end - start);
|
||||
for (int jd = start; jd < end; ++jd)
|
||||
list.append(QDateTime(QDate::fromJulianDay(jd), QTime::fromMSecsSinceStartOfDay(0), cet));
|
||||
|
@ -51,32 +51,24 @@ private Q_SLOTS:
|
||||
void transitionsReverse();
|
||||
};
|
||||
|
||||
static QVector<QByteArray> enoughZones()
|
||||
static QList<QByteArray> enoughZones()
|
||||
{
|
||||
#ifdef EXHAUSTIVE
|
||||
auto available = QTimeZone::availableTimeZoneIds();
|
||||
QVector<QByteArray> result;
|
||||
QList<QByteArray> result;
|
||||
result.reserve(available.size() + 1);
|
||||
for (conat auto &name : available)
|
||||
result << name;
|
||||
#else
|
||||
QVector<QByteArray> result{
|
||||
QByteArray("UTC"),
|
||||
// Those named overtly in tst_QDateTime:
|
||||
QByteArray("Europe/Oslo"),
|
||||
QByteArray("America/Vancouver"),
|
||||
QByteArray("Europe/Berlin"),
|
||||
QByteArray("America/Sao_Paulo"),
|
||||
QByteArray("Pacific/Auckland"),
|
||||
QByteArray("Australia/Eucla"),
|
||||
QByteArray("Asia/Kathmandu"),
|
||||
QByteArray("Pacific/Kiritimati"),
|
||||
QByteArray("Pacific/Apia"),
|
||||
QByteArray("UTC+12:00"),
|
||||
QByteArray("Australia/Sydney"),
|
||||
QByteArray("Asia/Singapore"),
|
||||
QByteArray("Australia/Brisbane")
|
||||
};
|
||||
QList<QByteArray> result { QByteArray("UTC"),
|
||||
// Those named overtly in tst_QDateTime:
|
||||
QByteArray("Europe/Oslo"), QByteArray("America/Vancouver"),
|
||||
QByteArray("Europe/Berlin"), QByteArray("America/Sao_Paulo"),
|
||||
QByteArray("Pacific/Auckland"), QByteArray("Australia/Eucla"),
|
||||
QByteArray("Asia/Kathmandu"), QByteArray("Pacific/Kiritimati"),
|
||||
QByteArray("Pacific/Apia"), QByteArray("UTC+12:00"),
|
||||
QByteArray("Australia/Sydney"), QByteArray("Asia/Singapore"),
|
||||
QByteArray("Australia/Brisbane") };
|
||||
#endif
|
||||
result << QByteArray("Vulcan/ShiKahr"); // invalid: also worth testing
|
||||
return result;
|
||||
|
@ -25,10 +25,10 @@
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
// This file contains benchmarks for comparing QVector against std::vector
|
||||
// This file contains benchmarks for comparing QList against std::vector
|
||||
|
||||
#include <QtCore>
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
#include <vector>
|
||||
|
||||
#include <qtest.h>
|
||||
@ -51,13 +51,13 @@ T * f(T *ts) // dummy function to prevent code from being optimized away by the
|
||||
return ts;
|
||||
}
|
||||
|
||||
// This subclass implements the use cases using QVector as efficiently as possible.
|
||||
template <typename T>
|
||||
class UseCases_QVector : public UseCases<T>
|
||||
// This subclass implements the use cases using QList as efficiently as possible.
|
||||
template<typename T>
|
||||
class UseCases_QList : public UseCases<T>
|
||||
{
|
||||
void insert(int size)
|
||||
{
|
||||
QVector<T> v;
|
||||
QList<T> v;
|
||||
T t;
|
||||
QBENCHMARK {
|
||||
for (int i = 0; i < size; ++i)
|
||||
@ -67,7 +67,7 @@ class UseCases_QVector : public UseCases<T>
|
||||
|
||||
void lookup(int size)
|
||||
{
|
||||
QVector<T> v;
|
||||
QList<T> v;
|
||||
|
||||
T t;
|
||||
for (int i = 0; i < size; ++i)
|
||||
@ -127,17 +127,17 @@ class tst_vector_vs_std : public QObject
|
||||
public:
|
||||
tst_vector_vs_std()
|
||||
{
|
||||
useCases_QVector_int = new UseCases_QVector<int>;
|
||||
useCases_QList_int = new UseCases_QList<int>;
|
||||
useCases_stdvector_int = new UseCases_stdvector<int>;
|
||||
|
||||
useCases_QVector_Large = new UseCases_QVector<Large>;
|
||||
useCases_QList_Large = new UseCases_QList<Large>;
|
||||
useCases_stdvector_Large = new UseCases_stdvector<Large>;
|
||||
}
|
||||
|
||||
private:
|
||||
UseCases<int> *useCases_QVector_int;
|
||||
UseCases<int> *useCases_QList_int;
|
||||
UseCases<int> *useCases_stdvector_int;
|
||||
UseCases<Large> *useCases_QVector_Large;
|
||||
UseCases<Large> *useCases_QList_Large;
|
||||
UseCases<Large> *useCases_stdvector_Large;
|
||||
|
||||
private slots:
|
||||
@ -159,7 +159,7 @@ void tst_vector_vs_std::insert_int_data()
|
||||
for (int size = 10; size < 20000; size += 100) {
|
||||
const QByteArray sizeString = QByteArray::number(size);
|
||||
QTest::newRow(QByteArray("std::vector-int--" + sizeString).constData()) << true << size;
|
||||
QTest::newRow(QByteArray("QVector-int--" + sizeString).constData()) << false << size;
|
||||
QTest::newRow(QByteArray("QList-int--" + sizeString).constData()) << false << size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -171,7 +171,7 @@ void tst_vector_vs_std::insert_int()
|
||||
if (useStd)
|
||||
useCases_stdvector_int->insert(size);
|
||||
else
|
||||
useCases_QVector_int->insert(size);
|
||||
useCases_QList_int->insert(size);
|
||||
}
|
||||
|
||||
void tst_vector_vs_std::insert_Large_data()
|
||||
@ -182,7 +182,7 @@ void tst_vector_vs_std::insert_Large_data()
|
||||
for (int size = 10; size < LARGE_MAX_SIZE; size += 100) {
|
||||
const QByteArray sizeString = QByteArray::number(size);
|
||||
QTest::newRow(QByteArray("std::vector-Large--" + sizeString).constData()) << true << size;
|
||||
QTest::newRow(QByteArray("QVector-Large--" + sizeString).constData()) << false << size;
|
||||
QTest::newRow(QByteArray("QList-Large--" + sizeString).constData()) << false << size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -194,7 +194,7 @@ void tst_vector_vs_std::insert_Large()
|
||||
if (useStd)
|
||||
useCases_stdvector_Large->insert(size);
|
||||
else
|
||||
useCases_QVector_Large->insert(size);
|
||||
useCases_QList_Large->insert(size);
|
||||
}
|
||||
|
||||
void tst_vector_vs_std::lookup_int_data()
|
||||
@ -205,7 +205,7 @@ void tst_vector_vs_std::lookup_int_data()
|
||||
for (int size = 10; size < 20000; size += 100) {
|
||||
const QByteArray sizeString = QByteArray::number(size);
|
||||
QTest::newRow(QByteArray("std::vector-int--" + sizeString).constData()) << true << size;
|
||||
QTest::newRow(QByteArray("QVector-int--" + sizeString).constData()) << false << size;
|
||||
QTest::newRow(QByteArray("QList-int--" + sizeString).constData()) << false << size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -217,7 +217,7 @@ void tst_vector_vs_std::lookup_int()
|
||||
if (useStd)
|
||||
useCases_stdvector_int->lookup(size);
|
||||
else
|
||||
useCases_QVector_int->lookup(size);
|
||||
useCases_QList_int->lookup(size);
|
||||
}
|
||||
|
||||
void tst_vector_vs_std::lookup_Large_data()
|
||||
@ -228,7 +228,7 @@ void tst_vector_vs_std::lookup_Large_data()
|
||||
for (int size = 10; size < LARGE_MAX_SIZE; size += 100) {
|
||||
const QByteArray sizeString = QByteArray::number(size);
|
||||
QTest::newRow(QByteArray("std::vector-Large--" + sizeString).constData()) << true << size;
|
||||
QTest::newRow(QByteArray("QVector-Large--" + sizeString).constData()) << false << size;
|
||||
QTest::newRow(QByteArray("QList-Large--" + sizeString).constData()) << false << size;
|
||||
}
|
||||
}
|
||||
|
||||
@ -240,7 +240,7 @@ void tst_vector_vs_std::lookup_Large()
|
||||
if (useStd)
|
||||
useCases_stdvector_Large->lookup(size);
|
||||
else
|
||||
useCases_QVector_Large->lookup(size);
|
||||
useCases_QList_Large->lookup(size);
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_vector_vs_std)
|
||||
|
@ -36,7 +36,7 @@
|
||||
#include <qalgorithms.h>
|
||||
#include <QStringList>
|
||||
#include <QString>
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -51,10 +51,10 @@ private slots:
|
||||
void sort();
|
||||
};
|
||||
|
||||
template <typename DataType>
|
||||
QVector<DataType> generateData(QString dataSetType, const int length)
|
||||
template<typename DataType>
|
||||
QList<DataType> generateData(QString dataSetType, const int length)
|
||||
{
|
||||
QVector<DataType> container;
|
||||
QList<DataType> container;
|
||||
if (dataSetType == "Random") {
|
||||
for (int i = 0; i < length; ++i)
|
||||
container.append(QRandomGenerator::global()->generate());
|
||||
@ -88,7 +88,7 @@ QVector<DataType> generateData(QString dataSetType, const int length)
|
||||
void tst_QAlgorithms::stableSort_data()
|
||||
{
|
||||
const int dataSize = 5000;
|
||||
QTest::addColumn<QVector<int> >("unsorted");
|
||||
QTest::addColumn<QList<int>>("unsorted");
|
||||
QTest::newRow("Equal") << (generateData<int>("Equal", dataSize));
|
||||
QTest::newRow("Ascending") << (generateData<int>("Ascending", dataSize));
|
||||
QTest::newRow("Descending") << (generateData<int>("Descending", dataSize));
|
||||
@ -98,10 +98,10 @@ void tst_QAlgorithms::stableSort_data()
|
||||
|
||||
void tst_QAlgorithms::stableSort()
|
||||
{
|
||||
QFETCH(QVector<int>, unsorted);
|
||||
QFETCH(QList<int>, unsorted);
|
||||
|
||||
QBENCHMARK {
|
||||
QVector<int> sorted = unsorted;
|
||||
QList<int> sorted = unsorted;
|
||||
qStableSort(sorted.begin(), sorted.end());
|
||||
}
|
||||
}
|
||||
@ -113,10 +113,10 @@ void tst_QAlgorithms::sort_data()
|
||||
|
||||
void tst_QAlgorithms::sort()
|
||||
{
|
||||
QFETCH(QVector<int>, unsorted);
|
||||
QFETCH(QList<int>, unsorted);
|
||||
|
||||
QBENCHMARK {
|
||||
QVector<int> sorted = unsorted;
|
||||
QList<int> sorted = unsorted;
|
||||
qSort(sorted.begin(), sorted.end());
|
||||
}
|
||||
}
|
||||
|
@ -26,7 +26,7 @@
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QVector>
|
||||
#include <QList>
|
||||
#include <vector>
|
||||
#include "qrawvector.h"
|
||||
|
||||
|
@ -310,7 +310,7 @@ void tst_QPainter::drawLine_data()
|
||||
QTest::addColumn<QLine>("line");
|
||||
QTest::addColumn<QPen>("pen");
|
||||
|
||||
QVector<QPen> pens;
|
||||
QList<QPen> pens;
|
||||
pens << QPen(Qt::black)
|
||||
<< QPen(Qt::black, 0, Qt::DashDotLine)
|
||||
<< QPen(Qt::black, 4)
|
||||
|
@ -55,7 +55,7 @@ public:
|
||||
uint m_total;
|
||||
uint m_iteration;
|
||||
|
||||
QVector<uint> iterationTimes;
|
||||
QList<uint> iterationTimes;
|
||||
};
|
||||
|
||||
void BenchWidget::paintEvent(QPaintEvent *)
|
||||
|
@ -37,7 +37,7 @@
|
||||
#include <QBuffer>
|
||||
#include <qtest.h>
|
||||
|
||||
Q_DECLARE_METATYPE(QVector<QTextLayout::FormatRange>)
|
||||
Q_DECLARE_METATYPE(QList<QTextLayout::FormatRange>)
|
||||
|
||||
class tst_QText: public QObject
|
||||
{
|
||||
@ -319,13 +319,13 @@ void tst_QText::layout()
|
||||
void tst_QText::formattedLayout_data()
|
||||
{
|
||||
QTest::addColumn<QString>("text");
|
||||
QTest::addColumn<QVector<QTextLayout::FormatRange> >("ranges");
|
||||
QTest::addColumn<QList<QTextLayout::FormatRange>>("ranges");
|
||||
|
||||
QTextCharFormat format;
|
||||
format.setForeground(QColor("steelblue"));
|
||||
|
||||
{
|
||||
QVector<QTextLayout::FormatRange> ranges;
|
||||
QList<QTextLayout::FormatRange> ranges;
|
||||
|
||||
QTextLayout::FormatRange formatRange;
|
||||
formatRange.format = format;
|
||||
@ -336,7 +336,7 @@ void tst_QText::formattedLayout_data()
|
||||
QTest::newRow("short-single") << m_shortLorem << ranges;
|
||||
}
|
||||
{
|
||||
QVector<QTextLayout::FormatRange> ranges;
|
||||
QList<QTextLayout::FormatRange> ranges;
|
||||
|
||||
QString text = m_lorem.repeated(100);
|
||||
const int width = 1;
|
||||
@ -355,7 +355,7 @@ void tst_QText::formattedLayout_data()
|
||||
void tst_QText::formattedLayout()
|
||||
{
|
||||
QFETCH(QString, text);
|
||||
QFETCH(QVector<QTextLayout::FormatRange>, ranges);
|
||||
QFETCH(QList<QTextLayout::FormatRange>, ranges);
|
||||
|
||||
QTextLayout layout(text);
|
||||
layout.setFormats(ranges);
|
||||
|
@ -49,7 +49,7 @@ protected:
|
||||
private:
|
||||
int x, y;
|
||||
QColor color;
|
||||
QVector<QPointF> stuff;
|
||||
QList<QPointF> stuff;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
@ -229,7 +229,7 @@ void tst_QTableView::spanSelectColumn()
|
||||
}
|
||||
}
|
||||
|
||||
typedef QVector<QRect> SpanList;
|
||||
typedef QList<QRect> SpanList;
|
||||
Q_DECLARE_METATYPE(SpanList)
|
||||
|
||||
void spansData()
|
||||
|
Loading…
x
Reference in New Issue
Block a user