mirror of
https://github.com/crystalidea/qt6windows7.git
synced 2025-07-08 02:17:43 +08:00
qt 6.5.1 original
This commit is contained in:
16
tests/benchmarks/corelib/tools/qhash/CMakeLists.txt
Normal file
16
tests/benchmarks/corelib/tools/qhash/CMakeLists.txt
Normal file
@ -0,0 +1,16 @@
|
||||
# Copyright (C) 2022 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
#####################################################################
|
||||
## tst_bench_qhash Binary:
|
||||
#####################################################################
|
||||
|
||||
qt_internal_add_benchmark(tst_bench_qhash
|
||||
SOURCES
|
||||
tst_bench_qhash.cpp
|
||||
outofline.cpp
|
||||
INCLUDE_DIRECTORIES
|
||||
.
|
||||
LIBRARIES
|
||||
Qt::Test
|
||||
)
|
56
tests/benchmarks/corelib/tools/qhash/outofline.cpp
Normal file
56
tests/benchmarks/corelib/tools/qhash/outofline.cpp
Normal file
@ -0,0 +1,56 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include "tst_bench_qhash.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
size_t qHash(const Qt4String &str)
|
||||
{
|
||||
qsizetype n = str.size();
|
||||
const QChar *p = str.unicode();
|
||||
uint h = 0;
|
||||
|
||||
while (n--) {
|
||||
h = (h << 4) + (*p++).unicode();
|
||||
h ^= (h & 0xf0000000) >> 23;
|
||||
h &= 0x0fffffff;
|
||||
}
|
||||
return h;
|
||||
}
|
||||
|
||||
size_t qHash(const Qt50String &key, size_t seed)
|
||||
{
|
||||
const QChar *p = key.unicode();
|
||||
qsizetype len = key.size();
|
||||
size_t h = seed;
|
||||
for (int i = 0; i < len; ++i)
|
||||
h = 31 * h + p[i].unicode();
|
||||
return h;
|
||||
}
|
||||
|
||||
// The Java's hashing algorithm for strings is a variation of D. J. Bernstein
|
||||
// hashing algorithm appeared here http://cr.yp.to/cdb/cdb.txt
|
||||
// and informally known as DJB33XX - DJB's 33 Times Xor.
|
||||
// Java uses DJB31XA, that is, 31 Times Add.
|
||||
// The original algorithm was a loop around "(h << 5) + h ^ c",
|
||||
// which is indeed "h * 33 ^ c"; it was then changed to
|
||||
// "(h << 5) - h ^ c", so "h * 31 ^ c", and the XOR changed to a sum:
|
||||
// "(h << 5) - h + c", which can save some assembly instructions.
|
||||
// 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)
|
||||
{
|
||||
const auto *p = reinterpret_cast<const char16_t *>(str.constData());
|
||||
const qsizetype len = str.size();
|
||||
|
||||
uint h = 0;
|
||||
|
||||
for (int i = 0; i < len; ++i)
|
||||
h = 31 * h + p[i];
|
||||
|
||||
return h;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
187
tests/benchmarks/corelib/tools/qhash/paths_small_data.txt
Normal file
187
tests/benchmarks/corelib/tools/qhash/paths_small_data.txt
Normal file
@ -0,0 +1,187 @@
|
||||
.
|
||||
./corelib.pro
|
||||
./kernel
|
||||
./kernel/kernel.pro
|
||||
./kernel/qobject
|
||||
./kernel/qobject/main.cpp
|
||||
./kernel/qobject/object.cpp
|
||||
./kernel/qobject/object.h
|
||||
./kernel/qobject/Makefile
|
||||
./kernel/qobject/qobject.pro
|
||||
./kernel/qvariant
|
||||
./kernel/qvariant/tst_qvariant.cpp
|
||||
./kernel/qvariant/Makefile
|
||||
./kernel/qvariant/qvariant.pro
|
||||
./kernel/qtimer_vs_qmetaobject
|
||||
./kernel/qtimer_vs_qmetaobject/tst_qtimer_vs_qmetaobject.cpp
|
||||
./kernel/qtimer_vs_qmetaobject/Makefile
|
||||
./kernel/qtimer_vs_qmetaobject/qtimer_vs_qmetaobject.pro
|
||||
./kernel/.pch
|
||||
./kernel/.pch/debug-shared
|
||||
./kernel/qmetaobject
|
||||
./kernel/qmetaobject/main.cpp
|
||||
./kernel/qmetaobject/qmetaobject.pro
|
||||
./kernel/qmetaobject/Makefile
|
||||
./kernel/Makefile
|
||||
./kernel/.obj
|
||||
./kernel/.obj/debug-shared
|
||||
./kernel/events
|
||||
./kernel/events/events.pro
|
||||
./kernel/events/main.cpp
|
||||
./kernel/events/Makefile
|
||||
./kernel/qmetatype
|
||||
./kernel/qmetatype/qmetatype.pro
|
||||
./kernel/qmetatype/Makefile
|
||||
./kernel/qmetatype/tst_qmetatype.cpp
|
||||
./.pch
|
||||
./.pch/debug-shared
|
||||
./text
|
||||
./text/text.pro
|
||||
./text/qregexp
|
||||
./text/qregexp/qregexp.qrc
|
||||
./text/qregexp/main.cpp
|
||||
./text/qregexp/Makefile
|
||||
./text/qregexp/qregexp.pro
|
||||
./text/qstringbuilder
|
||||
./text/qstringbuilder/main.cpp
|
||||
./text/qstringbuilder/Makefile
|
||||
./text/qstringbuilder/qstringbuilder.pro
|
||||
./text/qstring
|
||||
./text/qstring/generatelist.pl
|
||||
./text/qstring/data.h
|
||||
./text/qstring/qstring.pro
|
||||
./text/qstring/main.cpp
|
||||
./text/qstring/data.cpp
|
||||
./text/qstring/Makefile
|
||||
./text/qstring/utf-8.txt
|
||||
./text/qstringlist
|
||||
./text/qstringlist/qstringlist.pro
|
||||
./text/qstringlist/main.cpp
|
||||
./text/qstringlist/.gitignore
|
||||
./text/qstringlist/Makefile
|
||||
./text/qbytearray
|
||||
./text/qbytearray/qbytearray.pro
|
||||
./text/qbytearray/main.cpp
|
||||
./text/qbytearray/Makefile
|
||||
./text/.pch
|
||||
./text/.pch/debug-shared
|
||||
./tools
|
||||
./tools/tools.pro
|
||||
./tools/qvector
|
||||
./tools/qvector/tst_vector
|
||||
./tools/qvector/.pch
|
||||
./tools/qvector/.pch/debug-shared
|
||||
./tools/qvector/qrawvector.h
|
||||
./tools/qvector/main.cpp
|
||||
./tools/qvector/Makefile
|
||||
./tools/qvector/.moc
|
||||
./tools/qvector/.moc/release-shared
|
||||
./tools/qvector/.moc/release-shared/main.moc
|
||||
./tools/qvector/.obj
|
||||
./tools/qvector/.obj/release-shared
|
||||
./tools/qvector/.obj/release-shared/outofline.o
|
||||
./tools/qvector/.obj/release-shared/main.o
|
||||
./tools/qvector/outofline.cpp
|
||||
./tools/qvector/qvector.pro
|
||||
./tools/.pch
|
||||
./tools/.pch/debug-shared
|
||||
./tools/containers-sequential
|
||||
./tools/containers-sequential/containers-sequential.pro
|
||||
./tools/containers-sequential/main.cpp
|
||||
./tools/containers-sequential/Makefile
|
||||
./tools/containers-associative
|
||||
./tools/containers-associative/containers-associative.pro
|
||||
./tools/containers-associative/main.cpp
|
||||
./tools/containers-associative/Makefile
|
||||
./tools/qrect
|
||||
./tools/qrect/main.cpp
|
||||
./tools/qrect/Makefile
|
||||
./tools/qrect/qrect.pro
|
||||
./tools/Makefile
|
||||
./tools/qhash
|
||||
./tools/qhash/data.txt
|
||||
./tools/qhash/qhash_string.cpp
|
||||
./tools/qhash/.qhash_string.cpp.swp
|
||||
./tools/qhash/qhash.pro
|
||||
./tools/qhash/outofline.cpp
|
||||
./tools/.obj
|
||||
./tools/.obj/debug-shared
|
||||
./Makefile
|
||||
./.obj
|
||||
./.obj/debug-shared
|
||||
./plugin
|
||||
./plugin/plugin.pro
|
||||
./plugin/.pch
|
||||
./plugin/.pch/debug-shared
|
||||
./plugin/Makefile
|
||||
./plugin/.obj
|
||||
./plugin/.obj/debug-shared
|
||||
./plugin/quuid
|
||||
./plugin/quuid/tst_quuid.cpp
|
||||
./plugin/quuid/quuid.pro
|
||||
./plugin/quuid/Makefile
|
||||
./io
|
||||
./io/qtemporaryfile
|
||||
./io/qtemporaryfile/qtemporaryfile.pro
|
||||
./io/qtemporaryfile/main.cpp
|
||||
./io/qtemporaryfile/Makefile
|
||||
./io/qiodevice
|
||||
./io/qiodevice/qiodevice.pro
|
||||
./io/qiodevice/main.cpp
|
||||
./io/qiodevice/Makefile
|
||||
./io/qurl
|
||||
./io/qurl/main.cpp
|
||||
./io/qurl/Makefile
|
||||
./io/qurl/qurl.pro
|
||||
./io/qdir
|
||||
./io/qdir/.pch
|
||||
./io/qdir/.pch/debug-shared
|
||||
./io/qdir/qdir.pro
|
||||
./io/qdir/tree
|
||||
./io/qdir/tree/bench_qdir_tree.qrc
|
||||
./io/qdir/tree/tree.pro
|
||||
./io/qdir/tree/4.6.0-list.txt
|
||||
./io/qdir/tree/Makefile
|
||||
./io/qdir/tree/bench_qdir_tree.cpp
|
||||
./io/qdir/Makefile
|
||||
./io/qdir/.obj
|
||||
./io/qdir/.obj/debug-shared
|
||||
./io/qdir/10000
|
||||
./io/qdir/10000/10000.pro
|
||||
./io/qdir/10000/bench_qdir_10000.cpp
|
||||
./io/qdir/10000/Makefile
|
||||
./io/.pch
|
||||
./io/.pch/debug-shared
|
||||
./io/qfile
|
||||
./io/qfile/qfile.pro
|
||||
./io/qfile/main.cpp
|
||||
./io/qfile/Makefile
|
||||
./io/io.pro
|
||||
./io/qfileinfo
|
||||
./io/qfileinfo/qfileinfo.pro
|
||||
./io/qfileinfo/main.cpp
|
||||
./io/qfileinfo/Makefile
|
||||
./io/qdiriterator
|
||||
./io/qdiriterator/qfilesystemiterator.h
|
||||
./io/qdiriterator/main.cpp
|
||||
./io/qdiriterator/Makefile
|
||||
./io/qdiriterator/qfilesystemiterator.cpp
|
||||
./io/qdiriterator/qdiriterator.pro
|
||||
./io/Makefile
|
||||
./io/.obj
|
||||
./io/.obj/debug-shared
|
||||
./thread
|
||||
./thread/qmutex
|
||||
./thread/qmutex/tst_qmutex.cpp
|
||||
./thread/qmutex/Makefile
|
||||
./thread/qmutex/qmutex.pro
|
||||
./thread/qthreadstorage
|
||||
./thread/qthreadstorage/qthreadstorage.pro
|
||||
./thread/qthreadstorage/Makefile
|
||||
./thread/qthreadstorage/tst_qthreadstorage.cpp
|
||||
./thread/.pch
|
||||
./thread/.pch/debug-shared
|
||||
./thread/Makefile
|
||||
./thread/.obj
|
||||
./thread/.obj/debug-shared
|
||||
./thread/thread.pro
|
149
tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp
Normal file
149
tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.cpp
Normal file
@ -0,0 +1,149 @@
|
||||
// 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
|
||||
|
||||
#include "tst_bench_qhash.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QHash>
|
||||
#include <QString>
|
||||
#include <QStringList>
|
||||
#include <QUuid>
|
||||
#include <QTest>
|
||||
|
||||
|
||||
class tst_QHash : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void initTestCase();
|
||||
void qhash_current_data() { data(); }
|
||||
void qhash_current() { qhash_template<QString>(); }
|
||||
void qhash_qt50_data() { data(); }
|
||||
void qhash_qt50() { qhash_template<Qt50String>(); }
|
||||
void qhash_qt4_data() { data(); }
|
||||
void qhash_qt4() { qhash_template<Qt4String>(); }
|
||||
void qhash_javaString_data() { data(); }
|
||||
void qhash_javaString() { qhash_template<JavaString>(); }
|
||||
|
||||
void hashing_current_data() { data(); }
|
||||
void hashing_current() { hashing_template<QString>(); }
|
||||
void hashing_qt50_data() { data(); }
|
||||
void hashing_qt50() { hashing_template<Qt50String>(); }
|
||||
void hashing_qt4_data() { data(); }
|
||||
void hashing_qt4() { hashing_template<Qt4String>(); }
|
||||
void hashing_javaString_data() { data(); }
|
||||
void hashing_javaString() { hashing_template<JavaString>(); }
|
||||
|
||||
private:
|
||||
void data();
|
||||
template <typename String> void qhash_template();
|
||||
template <typename String> void hashing_template();
|
||||
|
||||
QStringList smallFilePaths;
|
||||
QStringList uuids;
|
||||
QStringList dict;
|
||||
QStringList numbers;
|
||||
};
|
||||
|
||||
///////////////////// QHash /////////////////////
|
||||
|
||||
#include <QDebug>
|
||||
|
||||
void tst_QHash::initTestCase()
|
||||
{
|
||||
// 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"));
|
||||
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 programmatically generates a series like:
|
||||
// AAAAAA
|
||||
// AAAAAB
|
||||
// AAAAAC
|
||||
// ...
|
||||
// AAAAAZ
|
||||
// AAAABZ
|
||||
// ...
|
||||
// AAAAZZ
|
||||
// AAABZZ
|
||||
QByteArray id("AAAAAAA");
|
||||
|
||||
if (dict.isEmpty()) {
|
||||
for (int i = id.size() - 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';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// string versions of numbers.
|
||||
for (int i = 5000000; i < 5005001; ++i)
|
||||
numbers.append(QString::number(i));
|
||||
}
|
||||
|
||||
void tst_QHash::data()
|
||||
{
|
||||
QTest::addColumn<QStringList>("items");
|
||||
QTest::newRow("paths-small") << smallFilePaths;
|
||||
QTest::newRow("uuids-list") << uuids;
|
||||
QTest::newRow("dictionary") << dict;
|
||||
QTest::newRow("numbers") << numbers;
|
||||
}
|
||||
|
||||
template <typename String> void tst_QHash::qhash_template()
|
||||
{
|
||||
QFETCH(QStringList, items);
|
||||
QHash<String, int> hash;
|
||||
|
||||
QList<String> realitems;
|
||||
foreach (const QString &s, items)
|
||||
realitems.append(s);
|
||||
|
||||
QBENCHMARK {
|
||||
for (int i = 0, n = realitems.size(); i != n; ++i) {
|
||||
hash[realitems.at(i)] = i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template <typename String> 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);
|
||||
|
||||
QBENCHMARK {
|
||||
for (int i = 0, n = realitems.size(); i != n; ++i)
|
||||
(void)qHash(realitems.at(i));
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QHash)
|
||||
|
||||
#include "tst_bench_qhash.moc"
|
36
tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.h
Normal file
36
tests/benchmarks/corelib/tools/qhash/tst_bench_qhash.h
Normal file
@ -0,0 +1,36 @@
|
||||
// Copyright (C) 2016 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QString>
|
||||
|
||||
struct Qt4String : QString
|
||||
{
|
||||
Qt4String() {}
|
||||
Qt4String(const QString &s) : QString(s) {}
|
||||
};
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
size_t qHash(const Qt4String &);
|
||||
QT_END_NAMESPACE
|
||||
|
||||
struct Qt50String : QString
|
||||
{
|
||||
Qt50String() {}
|
||||
Qt50String(const QString &s) : QString(s) {}
|
||||
};
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
size_t qHash(const Qt50String &, size_t seed = 0);
|
||||
QT_END_NAMESPACE
|
||||
|
||||
|
||||
struct JavaString : QString
|
||||
{
|
||||
JavaString() {}
|
||||
JavaString(const QString &s) : QString(s) {}
|
||||
};
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
size_t qHash(const JavaString &);
|
||||
QT_END_NAMESPACE
|
||||
|
Reference in New Issue
Block a user