diff options
author | João Abecasis <joao.abecasis@nokia.com> | 2012-03-08 12:01:25 +0100 |
---|---|---|
committer | João Abecasis <joao.abecasis@nokia.com> | 2012-03-08 12:02:41 +0100 |
commit | 79f2480c868523a7d8ffc9fb15055e8eab3237ba (patch) | |
tree | 8336143e8c09810dc97324970fed61af27e26a97 /tests/benchmarks | |
parent | 7e4f32993498db0e06346e32458a1ec7d0c7b3ec (diff) | |
parent | 12f221410fbe41d0b2efda4cd3289dfcf9044aa8 (diff) |
Merge remote-tracking branch 'origin/api_changes' into containters
Conflicts:
src/corelib/kernel/qmetaobject.cpp
src/corelib/kernel/qvariant.cpp
src/tools/moc/moc.h
Change-Id: I2cd3d95b41d2636738c6b98064864941e3b0b4e6
Diffstat (limited to 'tests/benchmarks')
11 files changed, 116 insertions, 106 deletions
diff --git a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp index a3cdd38e56..c80a946366 100644 --- a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -77,6 +77,9 @@ private slots: void constructCoreTypeCopy_data(); void constructCoreTypeCopy(); + void constructCustomType_data(); + void constructCustomType(); + void constructInPlace_data(); void constructInPlace(); void constructInPlaceCopy_data(); @@ -309,6 +312,24 @@ void tst_QMetaType::constructCoreTypeCopy() } } +void tst_QMetaType::constructCustomType_data() +{ + QTest::addColumn<int>("typeId"); + + QTest::newRow("BigClass") << qMetaTypeId<BigClass>(); +} + +void tst_QMetaType::constructCustomType() +{ + QFETCH(int, typeId); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) { + void *data = QMetaType::create(typeId, (void *)0); + QMetaType::destroy(typeId, data); + } + } +} + void tst_QMetaType::constructInPlace_data() { constructCoreType_data(); diff --git a/tests/benchmarks/corelib/tools/containers-associative/main.cpp b/tests/benchmarks/corelib/tools/containers-associative/main.cpp index 7f2e7b68ca..ab1c406708 100644 --- a/tests/benchmarks/corelib/tools/containers-associative/main.cpp +++ b/tests/benchmarks/corelib/tools/containers-associative/main.cpp @@ -72,8 +72,8 @@ void tst_associative_containers::insert_data() const QByteArray sizeString = QByteArray::number(size); - QTest::newRow(("hash--" + sizeString).constData()) << true << size; - QTest::newRow(("map--" + sizeString).constData()) << false << size; + QTest::newRow(QByteArray("hash--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("map--" + sizeString).constData()) << false << size; } } @@ -104,8 +104,8 @@ void tst_associative_containers::lookup_data() const QByteArray sizeString = QByteArray::number(size); - QTest::newRow(("hash--" + sizeString).constData()) << true << size; - QTest::newRow(("map--" + sizeString).constData()) << false << size; + QTest::newRow(QByteArray("hash--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("map--" + sizeString).constData()) << false << size; } } diff --git a/tests/benchmarks/corelib/tools/containers-sequential/main.cpp b/tests/benchmarks/corelib/tools/containers-sequential/main.cpp index e42a40b110..43eadb6633 100644 --- a/tests/benchmarks/corelib/tools/containers-sequential/main.cpp +++ b/tests/benchmarks/corelib/tools/containers-sequential/main.cpp @@ -176,8 +176,8 @@ void tst_vector_vs_std::insert_int_data() for (int size = 10; size < 20000; size += 100) { const QByteArray sizeString = QByteArray::number(size); - QTest::newRow(("std::vector-int--" + sizeString).constData()) << true << size; - QTest::newRow(("QVector-int--" + sizeString).constData()) << false << size; + QTest::newRow(QByteArray("std::vector-int--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("QVector-int--" + sizeString).constData()) << false << size; } } @@ -199,8 +199,8 @@ 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(("std::vector-Large--" + sizeString).constData()) << true << size; - QTest::newRow(("QVector-Large--" + sizeString).constData()) << false << size; + QTest::newRow(QByteArray("std::vector-Large--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("QVector-Large--" + sizeString).constData()) << false << size; } } @@ -222,8 +222,8 @@ void tst_vector_vs_std::lookup_int_data() for (int size = 10; size < 20000; size += 100) { const QByteArray sizeString = QByteArray::number(size); - QTest::newRow(("std::vector-int--" + sizeString).constData()) << true << size; - QTest::newRow(("QVector-int--" + sizeString).constData()) << false << size; + QTest::newRow(QByteArray("std::vector-int--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("QVector-int--" + sizeString).constData()) << false << size; } } @@ -245,8 +245,8 @@ 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(("std::vector-Large--" + sizeString).constData()) << true << size; - QTest::newRow(("QVector-Large--" + sizeString).constData()) << false << size; + QTest::newRow(QByteArray("std::vector-Large--" + sizeString).constData()) << true << size; + QTest::newRow(QByteArray("QVector-Large--" + sizeString).constData()) << false << size; } } diff --git a/tests/benchmarks/corelib/tools/qhash/main.cpp b/tests/benchmarks/corelib/tools/qhash/main.cpp index 18138cbd47..67396ffd57 100644 --- a/tests/benchmarks/corelib/tools/qhash/main.cpp +++ b/tests/benchmarks/corelib/tools/qhash/main.cpp @@ -54,72 +54,91 @@ class tst_QHash : public QObject Q_OBJECT private slots: + void initTestCase(); void qhash_qt4_data() { data(); } void qhash_qt4(); - void qhash_faster_data() { data(); } - void qhash_faster(); void javaString_data() { data(); } void javaString(); private: void data(); + + QStringList smallFilePaths; + QStringList uuids; + QStringList dict; + QStringList numbers; }; ///////////////////// QHash ///////////////////// -void tst_QHash::data() -{ - QTest::addColumn<QStringList>("items"); - static QStringList smallFilePaths; - - { - // small list of file paths - if (smallFilePaths.isEmpty()) { - QFile smallPathsData("paths_small_data.txt"); - QVERIFY(smallPathsData.open(QIODevice::ReadOnly)); - smallFilePaths = QString::fromLatin1(smallPathsData.readAll()).split(QLatin1Char('\n')); - Q_ASSERT(!smallFilePaths.isEmpty()); - } +#include <QDebug> - QTest::newRow("paths-small") << smallFilePaths; - } - - { - // list of UUIDs - static QStringList uuids; - if (uuids.isEmpty()) { - // guaranteed to be completely random, generated by http://xkcd.com/221/ - QUuid ns = QUuid("{f43d2ef3-2fe9-4563-a6f5-5a0100c2d699}"); - uuids.reserve(smallFilePaths.size()); - - foreach (const QString &path, smallFilePaths) - uuids.append(QUuid::createUuidV5(ns, path).toString()); +void tst_QHash::initTestCase() +{ + // small list of file paths + QFile smallPathsData("paths_small_data.txt"); + QVERIFY(smallPathsData.open(QIODevice::ReadOnly)); + smallFilePaths = QString::fromLatin1(smallPathsData.readAll()).split(QLatin1Char('\n')); + QVERIFY(!smallFilePaths.isEmpty()); + + // list of UUIDs + // guaranteed to be completely random, generated by http://xkcd.com/221/ + QUuid ns = QUuid("{f43d2ef3-2fe9-4563-a6f5-5a0100c2d699}"); + uuids.reserve(smallFilePaths.size()); + + foreach (const QString &path, smallFilePaths) + uuids.append(QUuid::createUuidV5(ns, path).toString()); + + + // lots of strings with alphabetical characters, vaguely reminiscent of + // a dictionary. + // + // this programatically generates a series like: + // AAAAAA + // AAAAAB + // AAAAAC + // ... + // AAAAAZ + // AAAABZ + // ... + // AAAAZZ + // AAABZZ + QByteArray id("AAAAAAA"); + + if (dict.isEmpty()) { + for (int i = id.length() - 1; i > 0;) { + dict.append(id); + char c = id.at(i); + id[i] = ++c; + + if (c == 'Z') { + // wrap to next digit + i--; + id[i] = 'A'; + } } - - QTest::newRow("uuids-list") << uuids; } + // string versions of numbers. + for (int i = 5000000; i < 5005001; ++i) + numbers.append(QString::number(i)); } -void tst_QHash::qhash_qt4() +void tst_QHash::data() { - QFETCH(QStringList, items); - QStringList realitems = items; // for copy/paste ease between benchmarks - QHash<QString, int> hash; - - QBENCHMARK { - for (int i = 0, n = realitems.size(); i != n; ++i) { - hash[realitems.at(i)] = i; - } - } + QTest::addColumn<QStringList>("items"); + QTest::newRow("paths-small") << smallFilePaths; + QTest::newRow("uuids-list") << uuids; + QTest::newRow("dictionary") << dict; + QTest::newRow("numbers") << numbers; } -void tst_QHash::qhash_faster() +void tst_QHash::qhash_qt4() { QFETCH(QStringList, items); - QHash<String, int> hash; + QHash<Qt4String, int> hash; - QList<String> realitems; + QList<Qt4String> realitems; foreach (const QString &s, items) realitems.append(s); diff --git a/tests/benchmarks/corelib/tools/qhash/main.h b/tests/benchmarks/corelib/tools/qhash/main.h index c4cf94e190..a865eaf7a6 100644 --- a/tests/benchmarks/corelib/tools/qhash/main.h +++ b/tests/benchmarks/corelib/tools/qhash/main.h @@ -41,14 +41,14 @@ #include <QString> -struct String : QString +struct Qt4String : QString { - String() {} - String(const QString &s) : QString(s) {} + Qt4String() {} + Qt4String(const QString &s) : QString(s) {} }; QT_BEGIN_NAMESPACE -uint qHash(const String &); +uint qHash(const Qt4String &); QT_END_NAMESPACE diff --git a/tests/benchmarks/corelib/tools/qhash/outofline.cpp b/tests/benchmarks/corelib/tools/qhash/outofline.cpp index 162c604a35..75d99f96f8 100644 --- a/tests/benchmarks/corelib/tools/qhash/outofline.cpp +++ b/tests/benchmarks/corelib/tools/qhash/outofline.cpp @@ -41,49 +41,19 @@ #include "main.h" -static void doHash(const unsigned short *p, uint &h) -{ -#if 1 - // Copied from static uint hash(const QChar *p, int n). - // Possibly not the cheapest way. - h = (h << 4) + (*p++); - h ^= (h & 0xf0000000) >> 23; - h &= 0x0fffffff; - - h = (h << 4) + (*p++); - h ^= (h & 0xf0000000) >> 23; - h &= 0x0fffffff; - - h = (h << 4) + (*p++); - h ^= (h & 0xf0000000) >> 23; - h &= 0x0fffffff; - - h = (h << 4) + (*p++); - h ^= (h & 0xf0000000) >> 23; - h &= 0x0fffffff; -#else - // Faster, but probably less spread. - h ^= *(unsigned int *)p; -#endif -} - QT_BEGIN_NAMESPACE -uint qHash(const String &str) +uint qHash(const Qt4String &str) { - const unsigned short *p = (unsigned short *)str.constData(); - const int s = str.size(); - switch (s) { - case 0: return 0; - case 1: return *p; - case 2: return *(unsigned int *)p; - case 3: return (*(unsigned int *)p) ^ *(p + 2); - //case 3: return (*p << 11) + (*(p + 1) << 22) + *(p + 2); - } + int n = str.length(); + const QChar *p = str.unicode(); uint h = 0; - doHash(p, h); - doHash(p + s / 2 - 2, h); - doHash(p + s - 4, h); + + while (n--) { + h = (h << 4) + (*p++).unicode(); + h ^= (h & 0xf0000000) >> 23; + h &= 0x0fffffff; + } return h; } diff --git a/tests/benchmarks/dbus/qdbustype/main.cpp b/tests/benchmarks/dbus/qdbustype/main.cpp index 0e0ce358bb..b0f6988425 100644 --- a/tests/benchmarks/dbus/qdbustype/main.cpp +++ b/tests/benchmarks/dbus/qdbustype/main.cpp @@ -56,7 +56,7 @@ private Q_SLOTS: static inline void benchmarkAddRow(const char *name, const char *data) { - QTest::newRow(QByteArray("native-") + name) << data << true; + QTest::newRow(QByteArray(QByteArray("native-") + name)) << data << true; QTest::newRow(name) << data << false; } diff --git a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/themeevent.cpp b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/themeevent.cpp index 1ebdf2e0bb..3ce3d5c2c1 100644 --- a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/themeevent.cpp +++ b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/themeevent.cpp @@ -41,7 +41,7 @@ #include "themeevent.h" -ThemeEvent::ThemeEvent( QString newTheme, Type type) : QEvent(type), +ThemeEvent::ThemeEvent( const QString &newTheme, Type type) : QEvent(type), m_theme(newTheme) { diff --git a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/themeevent.h b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/themeevent.h index c98f90da55..3603b5966f 100644 --- a/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/themeevent.h +++ b/tests/benchmarks/gui/graphicsview/functional/GraphicsViewBenchmark/widgets/themeevent.h @@ -50,7 +50,7 @@ static QEvent::Type ThemeEventType = (QEvent::Type) 1010; class ThemeEvent : public QEvent { public: - ThemeEvent(QString newTheme, QEvent::Type type = ThemeEventType ); + explicit ThemeEvent(const QString &newTheme, QEvent::Type type = ThemeEventType ); ~ThemeEvent(); public: diff --git a/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp b/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp index fcddf5ed90..45acd41749 100644 --- a/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp +++ b/tests/benchmarks/gui/styles/qstylesheetstyle/main.cpp @@ -153,9 +153,9 @@ void tst_qstylesheetstyle::grid_data() QTest::addColumn<int>("N"); for (int n = 5; n <= 25; n += 5) { const QByteArray nString = QByteArray::number(n*n); - QTest::newRow(("simple--" + nString).constData()) << false << false << n; - QTest::newRow(("events--" + nString).constData()) << true << false << n; - QTest::newRow(("show--" + nString).constData()) << true << true << n; + QTest::newRow(QByteArray("simple--" + nString).constData()) << false << false << n; + QTest::newRow(QByteArray("events--" + nString).constData()) << true << false << n; + QTest::newRow(QByteArray("show--" + nString).constData()) << true << true << n; } } diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp index fe9efa55b7..16f9625eba 100644 --- a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -530,7 +530,7 @@ void tst_qnetworkreply::downloadPerformance() // unlike the above function, this one tries to send as fast as possible // and measures how fast it was. TimedSender sender(5000); - QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(sender.serverPort()) + "/?bare=1"); + QNetworkRequest request(QUrl(QStringLiteral("debugpipe://127.0.0.1:") + QString::number(sender.serverPort()) + QStringLiteral("/?bare=1"))); QNetworkReplyPtr reply = manager.get(request); DataReader reader(reply, false); @@ -552,7 +552,7 @@ void tst_qnetworkreply::uploadPerformance() DataGenerator generator; - QNetworkRequest request("debugpipe://127.0.0.1:" + QString::number(reader.serverPort()) + "/?bare=1"); + QNetworkRequest request(QUrl(QStringLiteral("debugpipe://127.0.0.1:") + QString::number(reader.serverPort()) + QStringLiteral("/?bare=1"))); QNetworkReplyPtr reply = manager.put(request, &generator); generator.start(); connect(&reader, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop())); |