diff options
Diffstat (limited to 'tests/benchmarks/corelib/tools')
20 files changed, 277 insertions, 98 deletions
diff --git a/tests/benchmarks/corelib/tools/containers-associative/tst_bench_containers_associative.cpp b/tests/benchmarks/corelib/tools/containers-associative/tst_bench_containers_associative.cpp index ee711abf85..a5618cfcaf 100644 --- a/tests/benchmarks/corelib/tools/containers-associative/tst_bench_containers_associative.cpp +++ b/tests/benchmarks/corelib/tools/containers-associative/tst_bench_containers_associative.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QString> #include <QMap> #include <QHash> diff --git a/tests/benchmarks/corelib/tools/containers-sequential/tst_bench_containers_sequential.cpp b/tests/benchmarks/corelib/tools/containers-sequential/tst_bench_containers_sequential.cpp index 76d93cd85c..78c8016664 100644 --- a/tests/benchmarks/corelib/tools/containers-sequential/tst_bench_containers_sequential.cpp +++ b/tests/benchmarks/corelib/tools/containers-sequential/tst_bench_containers_sequential.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only // This file contains benchmarks for comparing QList against std::vector #include <QtCore> @@ -65,7 +65,7 @@ class UseCases_stdvector : public UseCases<T> void insert(int size) override { std::vector<T> v; - T t; + T t = {}; QBENCHMARK { for (int i = 0; i < size; ++i) v.push_back(t); @@ -76,7 +76,7 @@ class UseCases_stdvector : public UseCases<T> { std::vector<T> v; - T t; + T t = {}; for (int i = 0; i < size; ++i) v.push_back(t); diff --git a/tests/benchmarks/corelib/tools/qcontiguouscache/tst_bench_qcontiguouscache.cpp b/tests/benchmarks/corelib/tools/qcontiguouscache/tst_bench_qcontiguouscache.cpp index e23e762154..ae2cf471b0 100644 --- a/tests/benchmarks/corelib/tools/qcontiguouscache/tst_bench_qcontiguouscache.cpp +++ b/tests/benchmarks/corelib/tools/qcontiguouscache/tst_bench_qcontiguouscache.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QObject> #include <QTest> diff --git a/tests/benchmarks/corelib/tools/qcryptographichash/tst_bench_qcryptographichash.cpp b/tests/benchmarks/corelib/tools/qcryptographichash/tst_bench_qcryptographichash.cpp index 85bf863f9d..9f2d1c57f2 100644 --- a/tests/benchmarks/corelib/tools/qcryptographichash/tst_bench_qcryptographichash.cpp +++ b/tests/benchmarks/corelib/tools/qcryptographichash/tst_bench_qcryptographichash.cpp @@ -1,13 +1,19 @@ +// Copyright (C) 2023 The Qt Company Ltd. // Copyright (C) 2017 Intel Corporation. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QByteArray> #include <QCryptographicHash> #include <QFile> +#include <QMetaEnum> +#include <QMessageAuthenticationCode> #include <QRandomGenerator> #include <QString> #include <QTest> +#include <qxpfunctional.h> +#include <numeric> + #include <time.h> class tst_QCryptographicHash : public QObject @@ -15,6 +21,8 @@ class tst_QCryptographicHash : public QObject Q_OBJECT QByteArray blockOfData; + using Algorithm = QCryptographicHash::Algorithm; + public: tst_QCryptographicHash(); @@ -25,62 +33,24 @@ private Q_SLOTS: void addData(); void addDataChunked_data() { hash_data(); } void addDataChunked(); + + // QMessageAuthenticationCode: + void hmac_hash_data() { hash_data(); } + void hmac_hash(); + void hmac_addData_data() { hash_data(); } + void hmac_addData(); + void hmac_setKey_data(); + void hmac_setKey(); }; -const int MaxCryptoAlgorithm = QCryptographicHash::Sha3_512; const int MaxBlockSize = 65536; -const char *algoname(int i) +static void for_each_algorithm(qxp::function_ref<void(QCryptographicHash::Algorithm, const char*) const> f) { - switch (QCryptographicHash::Algorithm(i)) { - case QCryptographicHash::Md4: - return "md4-"; - case QCryptographicHash::Md5: - return "md5-"; - case QCryptographicHash::Sha1: - return "sha1-"; - case QCryptographicHash::Sha224: - return "sha2_224-"; - case QCryptographicHash::Sha256: - return "sha2_256-"; - case QCryptographicHash::Sha384: - return "sha2_384-"; - case QCryptographicHash::Sha512: - return "sha2_512-"; - case QCryptographicHash::Sha3_224: - return "sha3_224-"; - case QCryptographicHash::Sha3_256: - return "sha3_256-"; - case QCryptographicHash::Sha3_384: - return "sha3_384-"; - case QCryptographicHash::Sha3_512: - return "sha3_512-"; - case QCryptographicHash::Keccak_224: - return "keccak_224-"; - case QCryptographicHash::Keccak_256: - return "keccak_256-"; - case QCryptographicHash::Keccak_384: - return "keccak_384-"; - case QCryptographicHash::Keccak_512: - return "keccak_512-"; - case QCryptographicHash::Blake2b_160: - return "blake2b_160-"; - case QCryptographicHash::Blake2b_256: - return "blake2b_256-"; - case QCryptographicHash::Blake2b_384: - return "blake2b_384-"; - case QCryptographicHash::Blake2b_512: - return "blake2b_512-"; - case QCryptographicHash::Blake2s_128: - return "blake2s_128-"; - case QCryptographicHash::Blake2s_160: - return "blake2s_160-"; - case QCryptographicHash::Blake2s_224: - return "blake2s_224-"; - case QCryptographicHash::Blake2s_256: - return "blake2s_256-"; - } - Q_UNREACHABLE_RETURN(nullptr); + using A = QCryptographicHash::Algorithm; + static const auto metaEnum = QMetaEnum::fromType<A>(); + for (int i = 0, value = metaEnum.value(i); value != -1; value = metaEnum.value(++i)) + f(A(value), metaEnum.key(i)); } tst_QCryptographicHash::tst_QCryptographicHash() @@ -100,7 +70,7 @@ tst_QCryptographicHash::tst_QCryptographicHash() void tst_QCryptographicHash::hash_data() { - QTest::addColumn<int>("algorithm"); + QTest::addColumn<Algorithm>("algo"); QTest::addColumn<QByteArray>("data"); static const int datasizes[] = { 0, 1, 64, 65, 512, 4095, 4096, 4097, 65536 }; @@ -108,42 +78,56 @@ void tst_QCryptographicHash::hash_data() Q_ASSERT(datasizes[i] < MaxBlockSize); QByteArray data = QByteArray::fromRawData(blockOfData.constData(), datasizes[i]); - for (int algo = QCryptographicHash::Md4; algo <= MaxCryptoAlgorithm; ++algo) - QTest::newRow(algoname(algo) + QByteArray::number(datasizes[i])) << algo << data; + for_each_algorithm([&] (Algorithm algo, const char *name) { + if (algo == Algorithm::NumAlgorithms) + return; + QTest::addRow("%s-%d", name, datasizes[i]) << algo << data; + }); } } +#define SKIP_IF_NOT_SUPPORTED(algo) do { \ + if (!QCryptographicHash::supportsAlgorithm(algo)) \ + QSKIP("This algorithm is not supported in this configuration"); \ + } while (false) \ + /* end */ + void tst_QCryptographicHash::hash() { - QFETCH(int, algorithm); + QFETCH(const Algorithm, algo); QFETCH(QByteArray, data); - QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); + SKIP_IF_NOT_SUPPORTED(algo); + QBENCHMARK { - QCryptographicHash::hash(data, algo); + [[maybe_unused]] + auto r = QCryptographicHash::hash(data, algo); } } void tst_QCryptographicHash::addData() { - QFETCH(int, algorithm); + QFETCH(const Algorithm, algo); QFETCH(QByteArray, data); - QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); + SKIP_IF_NOT_SUPPORTED(algo); + QCryptographicHash hash(algo); QBENCHMARK { hash.reset(); hash.addData(data); - hash.result(); + [[maybe_unused]] + auto r = hash.resultView(); } } void tst_QCryptographicHash::addDataChunked() { - QFETCH(int, algorithm); + QFETCH(const Algorithm, algo); QFETCH(QByteArray, data); - QCryptographicHash::Algorithm algo = QCryptographicHash::Algorithm(algorithm); + SKIP_IF_NOT_SUPPORTED(algo); + QCryptographicHash hash(algo); QBENCHMARK { hash.reset(); @@ -153,10 +137,87 @@ void tst_QCryptographicHash::addDataChunked() hash.addData({data.constData() + 64 * i, 64}); hash.addData({data.constData() + data.size() / 64 * 64, data.size() % 64}); - hash.result(); + [[maybe_unused]] + auto r = hash.resultView(); + } +} + +static QByteArray hmacKey() { + static QByteArray key = [] { + QByteArray result(277, Qt::Uninitialized); + std::iota(result.begin(), result.end(), uchar(0)); // uchar so wraps after UCHAR_MAX + return result; + }(); + return key; +} + +void tst_QCryptographicHash::hmac_hash() +{ + QFETCH(const Algorithm, algo); + QFETCH(const QByteArray, data); + + SKIP_IF_NOT_SUPPORTED(algo); + + const auto key = hmacKey(); + QBENCHMARK { + [[maybe_unused]] + auto r = QMessageAuthenticationCode::hash(data, key, algo); + } +} + +void tst_QCryptographicHash::hmac_addData() +{ + QFETCH(const Algorithm, algo); + QFETCH(const QByteArray, data); + + SKIP_IF_NOT_SUPPORTED(algo); + + const auto key = hmacKey(); + QMessageAuthenticationCode mac(algo, key); + QBENCHMARK { + mac.reset(); + mac.addData(data); + [[maybe_unused]] + auto r = mac.resultView(); + } +} + +void tst_QCryptographicHash::hmac_setKey_data() +{ + QTest::addColumn<Algorithm>("algo"); + for_each_algorithm([] (Algorithm algo, const char *name) { + if (algo == Algorithm::NumAlgorithms) + return; + QTest::addRow("%s", name) << algo; + }); +} + +void tst_QCryptographicHash::hmac_setKey() +{ + QFETCH(const Algorithm, algo); + + SKIP_IF_NOT_SUPPORTED(algo); + + const QByteArrayList keys = [] { + QByteArrayList result; + const auto fullKey = hmacKey(); + result.reserve(fullKey.size()); + for (auto i = fullKey.size(); i > 0; --i) + result.push_back(fullKey.sliced(i)); + return result; + }(); + + QMessageAuthenticationCode mac(algo); + QBENCHMARK { + for (const auto &key : keys) { + mac.setKey(key); + mac.addData("abc", 3); // avoid lazy setKey() + } } } +#undef SKIP_IF_NOT_SUPPORTED + QTEST_APPLESS_MAIN(tst_QCryptographicHash) #include "tst_bench_qcryptographichash.moc" diff --git a/tests/benchmarks/corelib/tools/qhash/CMakeLists.txt b/tests/benchmarks/corelib/tools/qhash/CMakeLists.txt index 1958f86dd5..9002cc0723 100644 --- a/tests/benchmarks/corelib/tools/qhash/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qhash/CMakeLists.txt @@ -9,6 +9,8 @@ qt_internal_add_benchmark(tst_bench_qhash SOURCES tst_bench_qhash.cpp outofline.cpp + NO_PCH_SOURCES + tst_bench_qhash.cpp # undef QT_NO_FOREACH INCLUDE_DIRECTORIES . LIBRARIES diff --git a/tests/benchmarks/corelib/tools/qhash/outofline.cpp b/tests/benchmarks/corelib/tools/qhash/outofline.cpp index 6ad1a4c52a..5b16c36ffb 100644 --- a/tests/benchmarks/corelib/tools/qhash/outofline.cpp +++ b/tests/benchmarks/corelib/tools/qhash/outofline.cpp @@ -1,11 +1,11 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include "tst_bench_qhash.h" QT_BEGIN_NAMESPACE -size_t qHash(const Qt4String &str) +size_t qHash(const Qt4String &str, size_t /* never used */) { qsizetype n = str.size(); const QChar *p = str.unicode(); @@ -40,9 +40,9 @@ size_t qHash(const Qt50String &key, size_t seed) // Still, we can avoid writing the multiplication as "(h << 5) - h" // -- the compiler will turn it into a shift and an addition anyway // (for instance, gcc 4.4 does that even at -O0). -size_t qHash(const JavaString &str) +size_t qHash(const JavaString &str, size_t /* never used */) { - const unsigned short *p = (unsigned short *)str.constData(); + const auto *p = reinterpret_cast<const char16_t *>(str.constData()); const qsizetype len = str.size(); uint h = 0; diff --git a/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp b/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp index fd0a74b52a..1a62a48437 100644 --- a/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp +++ b/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp @@ -1,6 +1,8 @@ // Copyright (C) 2016 The Qt Company Ltd. // Copyright (C) 2016 Intel Corporation. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses #include "tst_bench_qhash.h" @@ -11,6 +13,8 @@ #include <QUuid> #include <QTest> +static constexpr quint64 RandomSeed32 = 1045982819; +static constexpr quint64 RandomSeed64 = QtPrivate::QHashCombine{}(RandomSeed32, RandomSeed32); class tst_QHash : public QObject { @@ -29,6 +33,8 @@ private slots: void hashing_current_data() { data(); } void hashing_current() { hashing_template<QString>(); } + void hashing_qbytearray_data() { data(); } + void hashing_qbytearray() { hashing_template<QByteArray>(); } void hashing_qt50_data() { data(); } void hashing_qt50() { hashing_template<Qt50String>(); } void hashing_qt4_data() { data(); } @@ -36,15 +42,25 @@ private slots: void hashing_javaString_data() { data(); } void hashing_javaString() { hashing_template<JavaString>(); } + void hashing_nonzero_current_data() { data(); } + void hashing_nonzero_current() { hashing_nonzero_template<QString>(); } + void hashing_nonzero_qbytearray_data() { data(); } + void hashing_nonzero_qbytearray() { hashing_nonzero_template<QByteArray>(); } + void hashing_nonzero_qlatin1string_data() { data(); } + void hashing_nonzero_qlatin1string() { hashing_nonzero_template<OwningLatin1String>(); } + private: void data(); template <typename String> void qhash_template(); - template <typename String> void hashing_template(); + template <typename String, size_t Seed = 0> void hashing_template(); + template <typename String> void hashing_nonzero_template() + { hashing_template<String, size_t(RandomSeed64)>(); } QStringList smallFilePaths; QStringList uuids; QStringList dict; QStringList numbers; + QStringList longstrings; }; ///////////////////// QHash ///////////////////// @@ -53,6 +69,8 @@ private: void tst_QHash::initTestCase() { + QHashSeed::setDeterministicGlobalSeed(); + // small list of strings (that happen to look like file paths produced long // ago by cd ../.. && find . -print, but that's irrelevant). QFile smallPathsData(QFINDTESTDATA("paths_small_data.txt")); @@ -64,10 +82,12 @@ void tst_QHash::initTestCase() // guaranteed to be completely random, generated by http://xkcd.com/221/ QUuid ns = QUuid("{f43d2ef3-2fe9-4563-a6f5-5a0100c2d699}"); uuids.reserve(smallFilePaths.size()); + longstrings.reserve(smallFilePaths.size()); foreach (const QString &path, smallFilePaths) uuids.append(QUuid::createUuidV5(ns, path).toString()); - + for (qsizetype i = 0; i < uuids.size(); ++i) + longstrings.append(uuids.at(i).repeated(8)); // lots of strings with alphabetical characters, vaguely reminiscent of // a dictionary. @@ -108,6 +128,7 @@ void tst_QHash::data() QTest::addColumn<QStringList>("items"); QTest::newRow("paths-small") << smallFilePaths; QTest::newRow("uuids-list") << uuids; + QTest::newRow("longstrings-list") << longstrings; QTest::newRow("dictionary") << dict; QTest::newRow("numbers") << numbers; } @@ -128,19 +149,30 @@ template <typename String> void tst_QHash::qhash_template() } } -template <typename String> void tst_QHash::hashing_template() +template <typename String, size_t Seed> void tst_QHash::hashing_template() { // just the hashing function QFETCH(QStringList, items); QList<String> realitems; realitems.reserve(items.size()); - foreach (const QString &s, items) - realitems.append(s); + foreach (const QString &s, items) { + if constexpr (std::is_same_v<QString::value_type, typename String::value_type>) { + realitems.append(s); + } else if constexpr (sizeof(typename String::value_type) == 1) { + realitems.append(String(s.toLatin1())); + } + } QBENCHMARK { - for (int i = 0, n = realitems.size(); i != n; ++i) - (void)qHash(realitems.at(i)); + for (int i = 0, n = realitems.size(); i != n; ++i) { + volatile size_t h = qHash(realitems.at(i), Seed); + (void)h; +#ifdef Q_CC_GNU + // "use" h + asm ("" : "+r" (h)); +#endif + } } } diff --git a/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.h b/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.h index f8a9d65f96..501b4a8b7f 100644 --- a/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.h +++ b/tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.h @@ -1,8 +1,20 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only +#include <QHashFunctions> #include <QString> +struct OwningLatin1String : QByteArray +{ + OwningLatin1String() = default; + OwningLatin1String(const QByteArray &a) : QByteArray(a) {} + OwningLatin1String(QByteArray &&a) : QByteArray(std::move(a)) {} +}; +QT_BEGIN_NAMESPACE +inline size_t qHash(const OwningLatin1String &s, size_t seed = 0) +{ return qHash(QLatin1StringView(s), seed); } +QT_END_NAMESPACE + struct Qt4String : QString { Qt4String() {} @@ -10,7 +22,7 @@ struct Qt4String : QString }; QT_BEGIN_NAMESPACE -size_t qHash(const Qt4String &); +size_t qHash(const Qt4String &, size_t = 0); QT_END_NAMESPACE struct Qt50String : QString @@ -31,6 +43,6 @@ struct JavaString : QString }; QT_BEGIN_NAMESPACE -size_t qHash(const JavaString &); +size_t qHash(const JavaString &, size_t = 0); QT_END_NAMESPACE diff --git a/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp b/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp index 7c014e7bc7..24691d1f71 100644 --- a/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp +++ b/tests/benchmarks/corelib/tools/qlist/tst_bench_qlist.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QList> #include <QTest> diff --git a/tests/benchmarks/corelib/tools/qmap/CMakeLists.txt b/tests/benchmarks/corelib/tools/qmap/CMakeLists.txt index 043ca2c7c2..4dc3dbb258 100644 --- a/tests/benchmarks/corelib/tools/qmap/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qmap/CMakeLists.txt @@ -1,8 +1,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qmap.pro. - ##################################################################### ## tst_bench_qmap Binary: ##################################################################### diff --git a/tests/benchmarks/corelib/tools/qmap/tst_bench_qmap.cpp b/tests/benchmarks/corelib/tools/qmap/tst_bench_qmap.cpp index f44d58edc5..db3c4fc7a2 100644 --- a/tests/benchmarks/corelib/tools/qmap/tst_bench_qmap.cpp +++ b/tests/benchmarks/corelib/tools/qmap/tst_bench_qmap.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QFile> #include <QMap> diff --git a/tests/benchmarks/corelib/tools/qrect/tst_bench_qrect.cpp b/tests/benchmarks/corelib/tools/qrect/tst_bench_qrect.cpp index dbf4c2db6c..0ba9e15963 100644 --- a/tests/benchmarks/corelib/tools/qrect/tst_bench_qrect.cpp +++ b/tests/benchmarks/corelib/tools/qrect/tst_bench_qrect.cpp @@ -1,7 +1,9 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only // This file contains benchmarks for QRect/QRectF functions. +#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses + #include <QDebug> #include <qtest.h> diff --git a/tests/benchmarks/corelib/tools/qringbuffer/tst_bench_qringbuffer.cpp b/tests/benchmarks/corelib/tools/qringbuffer/tst_bench_qringbuffer.cpp index 7acb0005ef..f352cd56a9 100644 --- a/tests/benchmarks/corelib/tools/qringbuffer/tst_bench_qringbuffer.cpp +++ b/tests/benchmarks/corelib/tools/qringbuffer/tst_bench_qringbuffer.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <private/qringbuffer_p.h> #include <QByteArray> diff --git a/tests/benchmarks/corelib/tools/qset/tst_bench_qset.cpp b/tests/benchmarks/corelib/tools/qset/tst_bench_qset.cpp index 9ac1a0449f..5bbec05aab 100644 --- a/tests/benchmarks/corelib/tools/qset/tst_bench_qset.cpp +++ b/tests/benchmarks/corelib/tools/qset/tst_bench_qset.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2016 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QSet> #include <QTest> @@ -9,12 +9,22 @@ class tst_QSet : public QObject Q_OBJECT private slots: + void initTestCase(); void intersect_int_data(); void intersect_int(); void intersect_complexType_data(); void intersect_complexType(); + void unite_int_data(); + void unite_int(); + void contains_then_insert_int_data(); + void contains_then_insert_int(); }; +void tst_QSet::initTestCase() +{ + QHashSeed::setDeterministicGlobalSeed(); +} + void tst_QSet::intersect_int_data() { QTest::addColumn<int>("lhsSize"); @@ -98,6 +108,70 @@ void tst_QSet::intersect_complexType() } } +void tst_QSet::unite_int_data() +{ + QTest::addColumn<int>("lhsSize"); + QTest::addColumn<int>("rhsSize"); + QTest::addColumn<int>("overlap"); + + QTest::newRow("1000000.unite(1000) - 0 overlap") << 1000000 << 1000 << 0; + QTest::newRow("1000000.unite(1000) - 100 overlap") << 1000000 << 1000 << 100; + QTest::newRow("1000000.unite(1000) - 1000 overlap") << 1000000 << 1000 << 1000; + QTest::newRow("1000.unite(1000000) - 0 overlap") << 1000 << 1000000 << 0; + QTest::newRow("1000.unite(1000000) - 100 overlap") << 1000 << 1000000 << 100; + QTest::newRow("1000.unite(1000000) - 1000 overlap") << 1000 << 1000000 << 1000; +} + +auto build_sets(int lhsSize, int rhsSize, int overlap) +{ + QSet<int> lhs; + for (int i = 0; i < lhsSize; ++i) + lhs.insert(i); + + QSet<int> rhs; + for (int i = lhsSize - overlap; i < rhsSize + lhsSize - overlap; ++i) + rhs.insert(i); + + return std::make_pair(lhs, rhs); +} + +void tst_QSet::unite_int() +{ + QFETCH(int, lhsSize); + QFETCH(int, rhsSize); + QFETCH(int, overlap); + + auto [lhs, rhs] = build_sets(lhsSize, rhsSize, overlap); + + QBENCHMARK { + QSet united = QSet(lhs).unite(rhs); + QCOMPARE(united.size(), lhsSize + rhsSize - overlap); + } +} + +void tst_QSet::contains_then_insert_int_data() +{ + unite_int_data(); +} + +void tst_QSet::contains_then_insert_int() +{ + QFETCH(int, lhsSize); + QFETCH(int, rhsSize); + QFETCH(int, overlap); + + auto [lhs, rhs] = build_sets(lhsSize, rhsSize, overlap); + + QBENCHMARK { + QSet copy(lhs); + for (auto i : rhs) { + if (!copy.contains(i)) + copy.insert(i); + } + QCOMPARE(copy.size(), lhsSize + rhsSize - overlap); + } +} + QTEST_MAIN(tst_QSet) #include "tst_bench_qset.moc" diff --git a/tests/benchmarks/corelib/tools/qsharedpointer/tst_bench_shared_ptr.cpp b/tests/benchmarks/corelib/tools/qsharedpointer/tst_bench_shared_ptr.cpp index b00bef96d4..6197863601 100644 --- a/tests/benchmarks/corelib/tools/qsharedpointer/tst_bench_shared_ptr.cpp +++ b/tests/benchmarks/corelib/tools/qsharedpointer/tst_bench_shared_ptr.cpp @@ -1,6 +1,6 @@ // Copyright (C) 2021 Klarälvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Marc Mutz <marc.mutz@kdab.com> // Copyright (C) 2022 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QObject> #include <QScopeGuard> diff --git a/tests/benchmarks/corelib/tools/qstack/tst_bench_qstack.cpp b/tests/benchmarks/corelib/tools/qstack/tst_bench_qstack.cpp index 468fb4b820..e0c8cda18c 100644 --- a/tests/benchmarks/corelib/tools/qstack/tst_bench_qstack.cpp +++ b/tests/benchmarks/corelib/tools/qstack/tst_bench_qstack.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2015 Robin Burchell <robin.burchell@viroteck.net> -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QStack> #include <QDebug> diff --git a/tests/benchmarks/corelib/tools/qvector/CMakeLists.txt b/tests/benchmarks/corelib/tools/qvector/CMakeLists.txt index 8acb6d15ef..df2fc8ec6a 100644 --- a/tests/benchmarks/corelib/tools/qvector/CMakeLists.txt +++ b/tests/benchmarks/corelib/tools/qvector/CMakeLists.txt @@ -1,8 +1,6 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause -# Generated from qvector.pro. - ##################################################################### ## tst_bench_qvector Binary: ##################################################################### diff --git a/tests/benchmarks/corelib/tools/qvector/outofline.cpp b/tests/benchmarks/corelib/tools/qvector/outofline.cpp index e2421e14e0..eb4756f710 100644 --- a/tests/benchmarks/corelib/tools/qvector/outofline.cpp +++ b/tests/benchmarks/corelib/tools/qvector/outofline.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QList> #include "qrawvector.h" diff --git a/tests/benchmarks/corelib/tools/qvector/qrawvector.h b/tests/benchmarks/corelib/tools/qvector/qrawvector.h index 606e3268e3..9e68b81285 100644 --- a/tests/benchmarks/corelib/tools/qvector/qrawvector.h +++ b/tests/benchmarks/corelib/tools/qvector/qrawvector.h @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QRAWVECTOR_H #define QRAWVECTOR_H diff --git a/tests/benchmarks/corelib/tools/qvector/tst_bench_qvector.cpp b/tests/benchmarks/corelib/tools/qvector/tst_bench_qvector.cpp index 2e2036110d..0486beed4e 100644 --- a/tests/benchmarks/corelib/tools/qvector/tst_bench_qvector.cpp +++ b/tests/benchmarks/corelib/tools/qvector/tst_bench_qvector.cpp @@ -1,5 +1,5 @@ // Copyright (C) 2021 The Qt Company Ltd. -// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0 +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QVector> #include <QDebug> |