summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-08-18 11:48:29 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-08-30 19:21:08 +0200
commit9004a2412ba1f9976c2c61f01223dff852208c42 (patch)
treef06abeec8b9cc66abf0e66cc9048c7a0ed02a360 /tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp
parentc2a6749af795386495b275684418d083410fa1e4 (diff)
Standardise layout and naming in corelib benchmarks
Make file names match CMake's test names (and those follow dir-name) and class names follow tst_ClassName pattern when testing ClassName. Purge comments about the qmake configs the CMakeLists.txt are generated from. Purge empty constructors and init/cleanup methods of classes. Fix petty coding style violations. Add qdir/tree/, qurl, qbench and qset benchmarks to their parent directories' lists of subdirs. Fix unused return error from qurl benchmark. Change-Id: Ifc15a3a46e71cf82ad0637753517e0df34049763 Reviewed-by: Andrei Golubev <andrei.golubev@qt.io> Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp')
-rw-r--r--tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp226
1 files changed, 226 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp
new file mode 100644
index 0000000000..d960cb41e2
--- /dev/null
+++ b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp
@@ -0,0 +1,226 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the test suite module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** GNU General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU
+** General Public License version 3 as published by the Free Software
+** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
+** included in the packaging of this file. Please review the following
+** information to ensure the GNU General Public License requirements will
+** be met: https://www.gnu.org/licenses/gpl-3.0.html.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QtTest/QTest>
+
+#include <QDirIterator>
+#include <QFile>
+#include <QString>
+#include <QStack>
+
+#include "../../../../../shared/filesystem.h"
+
+class tst_QDir_tree
+ : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QDir_tree()
+ : prefix("test-tree/"),
+ musicprefix(QLatin1String("music")),
+ photoprefix(QLatin1String("photos")),
+ sourceprefix(QLatin1String("source")),
+ musicsize(0),
+ photosize(0),
+ sourcesize(0)
+ {
+ }
+
+private:
+ QByteArray prefix;
+ QString musicprefix;
+ QString photoprefix;
+ QString sourceprefix;
+ qint64 musicsize;
+ qint64 photosize;
+ qint64 sourcesize;
+ FileSystem fs; // Uses QTemporaryDir to tidy away file tree created.
+
+private slots:
+ void initTestCase()
+ {
+ QFile list(":/4.6.0-list.txt");
+ QVERIFY(list.open(QIODevice::ReadOnly | QIODevice::Text));
+
+ QVERIFY(fs.createDirectory(prefix));
+
+ QStack<QByteArray> stack;
+ QByteArray line;
+ while (true) {
+ char ch;
+ if (!list.getChar(&ch))
+ break;
+ if (ch != ' ') {
+ line.append(ch);
+ continue;
+ }
+
+ int pop = 1;
+ if (!line.isEmpty())
+ pop = line.toInt();
+
+ while (pop) {
+ stack.pop();
+ --pop;
+ }
+
+ line = list.readLine().trimmed();
+ stack.push(line);
+
+ line = prefix;
+ for (const QByteArray &pathElement : qAsConst(stack))
+ line += pathElement;
+
+ if (line.endsWith('/'))
+ QVERIFY(fs.createDirectory(line));
+ else
+ QVERIFY(fs.createFile(line));
+
+ line.clear();
+ }
+
+ //Use case: music collection - 10 files in 100 directories (albums)
+ QVERIFY(fs.createDirectory(musicprefix));
+ for (int i=0;i<1000;i++) {
+ if ((i % 10) == 0)
+ QVERIFY(fs.createDirectory(QString("%1/directory%2").arg(musicprefix).arg(i/10)));
+ qint64 size = fs.createFileWithContent(QString("%1/directory%2/file%3").arg(musicprefix).arg(i/10).arg(i));
+ QVERIFY(size > 0);
+ musicsize += size;
+ }
+ //Use case: photos - 1000 files in 1 directory
+ QVERIFY(fs.createDirectory(photoprefix));
+ for (int i=0;i<1000;i++) {
+ qint64 size = fs.createFileWithContent(QString("%1/file%2").arg(photoprefix).arg(i));
+ QVERIFY(size > 0);
+ photosize += size;
+ }
+ //Use case: source - 10 files in 10 subdirectories in 10 directories (1000 total)
+ QVERIFY(fs.createDirectory(sourceprefix));
+ for (int i=0;i<1000;i++) {
+ if ((i % 100) == 0)
+ QVERIFY(fs.createDirectory(QString("%1/directory%2").arg(sourceprefix).arg(i/100)));
+ if ((i % 10) == 0)
+ QVERIFY(fs.createDirectory(QString("%1/directory%2/subdirectory%3").arg(sourceprefix).arg(i/100).arg(i/10)));
+ qint64 size = fs.createFileWithContent(QString("%1/directory%2/subdirectory%3/file%4").arg(sourceprefix).arg(i/100).arg(i/10).arg(i));
+ QVERIFY(size > 0);
+ sourcesize += size;
+ }
+ }
+
+ void fileSearch_data() const
+ {
+ QTest::addColumn<QStringList>("nameFilters");
+ QTest::addColumn<int>("filter");
+ QTest::addColumn<int>("entryCount");
+
+ QTest::newRow("*.cpp") << QStringList("*.cpp") << int(QDir::Files) << 3791;
+ QTest::newRow("executables")
+ << QStringList("*")
+ << int(QDir::Executable | QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot)
+ << 536;
+ }
+
+ void fileSearch() const
+ {
+ QFETCH(QStringList, nameFilters);
+ QFETCH(int, filter);
+ QFETCH(int, entryCount);
+
+ int count = 0;
+ QBENCHMARK {
+ // Recursive directory iteration
+ QDirIterator iterator(fs.absoluteFilePath(prefix),
+ nameFilters, QDir::Filter(filter),
+ QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
+
+ count = 0;
+ while (iterator.hasNext()) {
+ iterator.next();
+ ++count;
+ }
+
+ QCOMPARE(count, entryCount);
+ }
+
+ QCOMPARE(count, entryCount);
+ }
+
+ void traverseDirectory() const
+ {
+ int count = 0;
+ QBENCHMARK {
+ QDirIterator iterator(
+ fs.absoluteFilePath(prefix),
+ QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System,
+ QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
+
+ count = 0;
+ while (iterator.hasNext()) {
+ iterator.next();
+ ++count;
+ }
+
+ QCOMPARE(count, 11906);
+ }
+
+ QCOMPARE(count, 11906);
+ }
+
+ void thousandFiles_data() const
+ {
+ QTest::addColumn<QString>("dirName");
+ QTest::addColumn<qint64>("expectedSize");
+ QTest::newRow("music") << musicprefix << musicsize;
+ QTest::newRow("photos") << photoprefix << photosize;
+ QTest::newRow("src") << sourceprefix << sourcesize;
+ }
+
+ void thousandFiles() const
+ {
+ QFETCH(QString, dirName);
+ QFETCH(qint64, expectedSize);
+ QBENCHMARK {
+ qint64 totalsize = 0;
+ int count = 0;
+ QDirIterator iter(fs.absoluteFilePath(dirName),
+ QDir::Files, QDirIterator::Subdirectories);
+ while(iter.hasNext()) {
+ count++;
+ totalsize += iter.nextFileInfo().size();
+ }
+ QCOMPARE(count, 1000);
+ QCOMPARE(totalsize, expectedSize);
+ }
+ }
+};
+
+QTEST_MAIN(tst_QDir_tree)
+
+#include "tst_bench_qdir_tree.moc"