diff options
Diffstat (limited to 'tests/benchmarks/corelib/io/qdiriterator')
-rw-r--r-- | tests/benchmarks/corelib/io/qdiriterator/CMakeLists.txt | 7 | ||||
-rw-r--r-- | tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro | 13 | ||||
-rw-r--r-- | tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.cpp | 31 | ||||
-rw-r--r-- | tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.h | 29 | ||||
-rw-r--r-- | tests/benchmarks/corelib/io/qdiriterator/tst_bench_qdiriterator.cpp (renamed from tests/benchmarks/corelib/io/qdiriterator/main.cpp) | 157 |
5 files changed, 99 insertions, 138 deletions
diff --git a/tests/benchmarks/corelib/io/qdiriterator/CMakeLists.txt b/tests/benchmarks/corelib/io/qdiriterator/CMakeLists.txt index 8ba331a113..6a4579d35d 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/CMakeLists.txt +++ b/tests/benchmarks/corelib/io/qdiriterator/CMakeLists.txt @@ -1,4 +1,5 @@ -# Generated from qdiriterator.pro. +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause ##################################################################### ## tst_bench_qdiriterator Binary: @@ -6,9 +7,9 @@ qt_internal_add_benchmark(tst_bench_qdiriterator SOURCES - main.cpp + tst_bench_qdiriterator.cpp qfilesystemiterator.cpp qfilesystemiterator.h - PUBLIC_LIBRARIES + LIBRARIES Qt::Test ) diff --git a/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro b/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro deleted file mode 100644 index 0921b8424e..0000000000 --- a/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro +++ /dev/null @@ -1,13 +0,0 @@ -CONFIG += benchmark -QT = core testlib - -# Enable c++17 support for std::filesystem -qtConfig(cxx17_filesystem) { - CONFIG += c++17 - gcc:lessThan(QMAKE_GCC_MAJOR_VERSION, 9): \ - QMAKE_LFLAGS += -lstdc++fs -} - -TARGET = tst_bench_qdiriterator -SOURCES += main.cpp qfilesystemiterator.cpp -HEADERS += qfilesystemiterator.h diff --git a/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.cpp b/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.cpp index 10b1b90ce2..16b64cf362 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.cpp +++ b/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.cpp @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only /*! \since 4.5 @@ -85,7 +60,7 @@ #include <qplatformdefs.h> #ifdef Q_OS_WIN -# include <windows.h> +# include <qt_windows.h> #else # include <sys/stat.h> # include <sys/types.h> diff --git a/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.h b/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.h index 26bd2f59d9..479ce7b392 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.h +++ b/tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.h @@ -1,30 +1,5 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite 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$ -** -****************************************************************************/ +// Copyright (C) 2016 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #ifndef QFILESYSTEMITERATOR_H #define QFILESYSTEMITERATOR_H diff --git a/tests/benchmarks/corelib/io/qdiriterator/main.cpp b/tests/benchmarks/corelib/io/qdiriterator/tst_bench_qdiriterator.cpp index 367913338f..66448bf838 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/main.cpp +++ b/tests/benchmarks/corelib/io/qdiriterator/tst_bench_qdiriterator.cpp @@ -1,32 +1,8 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite 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$ -** -****************************************************************************/ +// Copyright (C) 2021 The Qt Company Ltd. +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only #include <QDebug> #include <QDirIterator> +#include <QDirListing> #include <QString> #include <qplatformdefs.h> @@ -48,40 +24,52 @@ #include <filesystem> #endif -class tst_qdiriterator : public QObject +using namespace Qt::StringLiterals; + +constexpr bool forceStat = false; + +class tst_QDirIterator : public QObject { Q_OBJECT void data(); + + const QDir::Filters dirFilters = + // QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot + QDir::AllEntries | QDir::Hidden + //QDir::Files | QDir::NoDotAndDotDot, + // QDir::Files, + ; + private slots: void posix(); void posix_data() { data(); } void diriterator(); void diriterator_data() { data(); } + void dirlisting(); + void dirlisting_data() { data(); } void fsiterator(); void fsiterator_data() { data(); } void stdRecursiveDirectoryIterator(); void stdRecursiveDirectoryIterator_data() { data(); } }; - -void tst_qdiriterator::data() +void tst_QDirIterator::data() { -#if defined(Q_OS_WIN) - const char *qtdir = "C:\\depot\\qt\\main"; -#else - const char *qtdir = ::getenv("QTDIR"); -#endif - if (!qtdir) { - fprintf(stderr, "QTDIR not set\n"); - exit(1); - } + const char hereRelative[] = "tests/benchmarks/corelib/io/qdiriterator"; + QByteArray dir(QT_TESTCASE_SOURCEDIR); + // qDebug("Source dir: %s", dir.constData()); + dir.chop(sizeof(hereRelative)); // Counts the '\0', making up for the omitted leading '/' + // qDebug("Root dir: %s", dir.constData()); QTest::addColumn<QByteArray>("dirpath"); - QByteArray ba = QByteArray(qtdir) + "/src/corelib"; - QByteArray ba1 = ba + "/io"; - QTest::newRow(ba) << ba; - //QTest::newRow(ba1) << ba1; + const QByteArray ba = dir + "/src/corelib"; + + if (!QFileInfo(QString::fromLocal8Bit(ba)).isDir()) + QSKIP("Missing Qt directory"); + + QTest::newRow("corelib") << ba; + QTest::newRow("corelib/io") << (ba + "/io"); } #ifdef Q_OS_WIN @@ -145,9 +133,20 @@ static int posix_helper(const char *dirpath) QByteArray ba = dirpath; ba += '/'; ba += entry->d_name; + bool isDir = false; +#if defined(_DIRENT_HAVE_D_TYPE) || defined(Q_OS_BSD4) + isDir = entry->d_type == DT_DIR; + if (forceStat) { + QT_STATBUF st; + QT_LSTAT(ba.constData(), &st); + } +#else // d_type not available >>> must stat() to see if it's a dir QT_STATBUF st; QT_LSTAT(ba.constData(), &st); - if (S_ISDIR(st.st_mode)) + isDir = S_ISDIR(st.st_mode); +#endif + + if (isDir) count += posix_helper(ba.constData()); } @@ -157,7 +156,7 @@ static int posix_helper(const char *dirpath) #endif -void tst_qdiriterator::posix() +void tst_QDirIterator::posix() { QFETCH(QByteArray, dirpath); @@ -175,7 +174,7 @@ void tst_qdiriterator::posix() qDebug() << count; } -void tst_qdiriterator::diriterator() +void tst_QDirIterator::diriterator() { QFETCH(QByteArray, dirpath); @@ -184,20 +183,40 @@ void tst_qdiriterator::diriterator() QBENCHMARK { int c = 0; - QDirIterator dir(dirpath, - //QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, - //QDir::AllEntries | QDir::Hidden, - QDir::Files, - QDirIterator::Subdirectories); + QDirIterator dir(dirpath, dirFilters, QDirIterator::Subdirectories); while (dir.hasNext()) { - dir.next(); + const auto fi = dir.nextFileInfo(); + if (forceStat) + fi.size(); //printf("%s\n", qPrintable(dir.fileName())); 0 && printf("%d %s\n", - dir.fileInfo().isDir(), - //qPrintable(dir.fileInfo().absoluteFilePath()), + fi.isDir(), + //qPrintable(fi.absoluteFilePath()), //qPrintable(dir.path()), - qPrintable(dir.filePath())); + qPrintable(fi.filePath())); + ++c; + } + count = c; + } + qDebug() << count; +} + +void tst_QDirIterator::dirlisting() +{ + QFETCH(QByteArray, dirpath); + + int count = 0; + + QBENCHMARK { + int c = 0; + + QDirListing dir(dirpath, dirFilters, QDirListing::IteratorFlag::Recursive); + + for (const auto &dirEntry : dir) { + const auto path = dirEntry.filePath(); + if (forceStat) + dirEntry.size(); ++c; } count = c; @@ -205,7 +224,7 @@ void tst_qdiriterator::diriterator() qDebug() << count; } -void tst_qdiriterator::fsiterator() +void tst_QDirIterator::fsiterator() { QFETCH(QByteArray, dirpath); @@ -216,14 +235,12 @@ void tst_qdiriterator::fsiterator() int c = 0; dump && printf("\n\n\n\n"); - QDirIteratorTest::QFileSystemIterator dir(dirpath, - //QDir::AllEntries | QDir::Hidden | QDir::NoDotAndDotDot, - //QDir::AllEntries | QDir::Hidden, - //QDir::Files | QDir::NoDotAndDotDot, - QDir::Files, - QDirIteratorTest::QFileSystemIterator::Subdirectories); + QDirIteratorTest::QFileSystemIterator dir( + dirpath, dirFilters, QDirIteratorTest::QFileSystemIterator::Subdirectories); for (; !dir.atEnd(); dir.next()) { + if (forceStat) + dir.fileInfo().size(); dump && printf("%d %s\n", dir.fileInfo().isDir(), //qPrintable(dir.fileInfo().absoluteFilePath()), @@ -237,17 +254,23 @@ void tst_qdiriterator::fsiterator() qDebug() << count; } -void tst_qdiriterator::stdRecursiveDirectoryIterator() +void tst_QDirIterator::stdRecursiveDirectoryIterator() { #if QT_CONFIG(cxx17_filesystem) QFETCH(QByteArray, dirpath); int count = 0; + namespace fs = std::filesystem; + std::error_code ec; + + // Note that fs::recursive_directory_iterator may be calling stat() internally, + // that depends on the implementation. So the benchmark times might "seem" higher + // than the other methods in this source file. QBENCHMARK { int c = 0; - for (auto obj : std::filesystem::recursive_directory_iterator(dirpath.data())) { - if (obj.is_directory()) + for (const auto &dirEntry : fs::recursive_directory_iterator(dirpath.data(), ec)) { + if (dirEntry.is_directory()) continue; c++; } @@ -259,6 +282,6 @@ void tst_qdiriterator::stdRecursiveDirectoryIterator() #endif } -QTEST_MAIN(tst_qdiriterator) +QTEST_MAIN(tst_QDirIterator) -#include "main.moc" +#include "tst_bench_qdiriterator.moc" |