summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/io
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/corelib/io')
-rw-r--r--tests/benchmarks/corelib/io/CMakeLists.txt8
-rw-r--r--tests/benchmarks/corelib/io/qdir/10000/CMakeLists.txt10
-rw-r--r--tests/benchmarks/corelib/io/qdir/10000/tst_bench_qdir_10000.cpp (renamed from tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp)153
-rw-r--r--tests/benchmarks/corelib/io/qdir/CMakeLists.txt3
-rw-r--r--tests/benchmarks/corelib/io/qdir/tree/4.6.0-list.txt2
-rw-r--r--tests/benchmarks/corelib/io/qdir/tree/CMakeLists.txt21
-rw-r--r--tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp (renamed from tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp)78
-rw-r--r--tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.qrc (renamed from tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.qrc)0
-rw-r--r--tests/benchmarks/corelib/io/qdiriterator/CMakeLists.txt7
-rw-r--r--tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.cpp31
-rw-r--r--tests/benchmarks/corelib/io/qdiriterator/qfilesystemiterator.h29
-rw-r--r--tests/benchmarks/corelib/io/qdiriterator/tst_bench_qdiriterator.cpp (renamed from tests/benchmarks/corelib/io/qdiriterator/main.cpp)157
-rw-r--r--tests/benchmarks/corelib/io/qfile/CMakeLists.txt10
-rw-r--r--tests/benchmarks/corelib/io/qfile/main.cpp707
-rw-r--r--tests/benchmarks/corelib/io/qfile/tst_bench_qfile.cpp593
-rw-r--r--tests/benchmarks/corelib/io/qfileinfo/CMakeLists.txt10
-rw-r--r--tests/benchmarks/corelib/io/qfileinfo/main.cpp115
-rw-r--r--tests/benchmarks/corelib/io/qfileinfo/tst_bench_qfileinfo.cpp77
-rw-r--r--tests/benchmarks/corelib/io/qiodevice/CMakeLists.txt10
-rw-r--r--tests/benchmarks/corelib/io/qiodevice/tst_bench_qiodevice.cpp (renamed from tests/benchmarks/corelib/io/qiodevice/main.cpp)42
-rw-r--r--tests/benchmarks/corelib/io/qprocess/CMakeLists.txt3
-rw-r--r--tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt5
-rw-r--r--tests/benchmarks/corelib/io/qprocess/testProcessLoopback/CMakeLists.txt5
-rw-r--r--tests/benchmarks/corelib/io/qprocess/testProcessLoopback/loopback.cpp19
-rw-r--r--tests/benchmarks/corelib/io/qprocess/testProcessLoopback/main.cpp44
-rw-r--r--tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp41
-rw-r--r--tests/benchmarks/corelib/io/qtemporaryfile/CMakeLists.txt10
-rw-r--r--tests/benchmarks/corelib/io/qtemporaryfile/main.cpp90
-rw-r--r--tests/benchmarks/corelib/io/qtemporaryfile/tst_bench_qtemporaryfile.cpp64
-rw-r--r--tests/benchmarks/corelib/io/qtextstream/CMakeLists.txt10
-rw-r--r--tests/benchmarks/corelib/io/qtextstream/tst_bench_qtextstream.cpp (renamed from tests/benchmarks/corelib/io/qtextstream/main.cpp)39
-rw-r--r--tests/benchmarks/corelib/io/qurl/CMakeLists.txt14
-rw-r--r--tests/benchmarks/corelib/io/qurl/tst_bench_qurl.cpp (renamed from tests/benchmarks/corelib/io/qurl/main.cpp)75
33 files changed, 1055 insertions, 1427 deletions
diff --git a/tests/benchmarks/corelib/io/CMakeLists.txt b/tests/benchmarks/corelib/io/CMakeLists.txt
index 3419c4a28c..e9bf2292c0 100644
--- a/tests/benchmarks/corelib/io/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/CMakeLists.txt
@@ -1,12 +1,14 @@
-# Generated from io.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(qdir)
add_subdirectory(qdiriterator)
add_subdirectory(qfile)
add_subdirectory(qfileinfo)
add_subdirectory(qiodevice)
-add_subdirectory(qtemporaryfile)
-add_subdirectory(qtextstream)
if(QT_FEATURE_process)
add_subdirectory(qprocess)
endif()
+add_subdirectory(qtemporaryfile)
+add_subdirectory(qtextstream)
+add_subdirectory(qurl)
diff --git a/tests/benchmarks/corelib/io/qdir/10000/CMakeLists.txt b/tests/benchmarks/corelib/io/qdir/10000/CMakeLists.txt
index e83c4e9acc..142c13aceb 100644
--- a/tests/benchmarks/corelib/io/qdir/10000/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qdir/10000/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from 10000.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qdir_10000 Binary:
@@ -6,10 +7,7 @@
qt_internal_add_benchmark(tst_bench_qdir_10000
SOURCES
- bench_qdir_10000.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qdir_10000.cpp
+ LIBRARIES
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:10000.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp b/tests/benchmarks/corelib/io/qdir/10000/tst_bench_qdir_10000.cpp
index 3184df0d7b..a53742b536 100644
--- a/tests/benchmarks/corelib/io/qdir/10000/bench_qdir_10000.cpp
+++ b/tests/benchmarks/corelib/io/qdir/10000/tst_bench_qdir_10000.cpp
@@ -1,36 +1,13 @@
-/****************************************************************************
-**
-** Copyright (C) 2016 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$
-**
-****************************************************************************/
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
#include <QTest>
#include <QDirIterator>
#ifdef Q_OS_WIN
-# include <windows.h>
+# include <qt_windows.h>
#else
# include <sys/stat.h>
# include <sys/types.h>
@@ -38,10 +15,12 @@
# include <unistd.h>
#endif
-class bench_QDir_10000 : public QObject{
- Q_OBJECT
+class tst_QDir_10000 : public QObject
+{
+ Q_OBJECT
public slots:
- void initTestCase() {
+ void initTestCase()
+ {
QDir testdir = QDir::tempPath();
const QString subfolder_name = QLatin1String("test_speed");
@@ -53,24 +32,16 @@ public slots:
file.open(QIODevice::WriteOnly);
}
}
- void cleanupTestCase() {
- {
- QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
- testdir.setSorting(QDir::Unsorted);
- testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
- foreach (const QString &filename, testdir.entryList()) {
- testdir.remove(filename);
- }
- }
- const QDir temp = QDir(QDir::tempPath());
- temp.rmdir(QLatin1String("test_speed"));
+ void cleanupTestCase()
+ {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ QVERIFY(testdir.removeRecursively());
}
private slots:
- void baseline() {}
-
- void sizeSpeed() {
- QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ void sizeSpeed()
+ {
QBENCHMARK {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted);
foreach (const QFileInfo &fileInfo, fileInfoList) {
fileInfo.isDir();
@@ -78,43 +49,47 @@ private slots:
}
}
}
- void sizeSpeedIterator() {
- QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ void sizeSpeedIterator()
+ {
QBENCHMARK {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
QDirIterator dit(testdir.path(), QDir::Files);
while (dit.hasNext()) {
- dit.next();
- dit.fileInfo().isDir();
- dit.fileInfo().size();
+ const auto fi = dit.nextFileInfo();
+ (void)fi.isDir();
+ (void)fi.size();
}
}
}
- void sizeSpeedWithoutFilter() {
- QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ void sizeSpeedWithoutFilter()
+ {
QBENCHMARK {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted);
foreach (const QFileInfo &fileInfo, fileInfoList) {
fileInfo.size();
}
}
}
- void sizeSpeedWithoutFilterIterator() {
- QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ void sizeSpeedWithoutFilterIterator()
+ {
QBENCHMARK {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
QDirIterator dit(testdir.path());
while (dit.hasNext()) {
- dit.next();
- dit.fileInfo().isDir();
- dit.fileInfo().size();
+ const auto fi = dit.nextFileInfo();
+ (void)fi.isDir();
+ (void)fi.size();
}
}
}
- void sizeSpeedWithoutFileInfoList() {
- QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
- testdir.setSorting(QDir::Unsorted);
+ void sizeSpeedWithoutFileInfoList()
+ {
QBENCHMARK {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ testdir.setSorting(QDir::Unsorted);
QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted);
foreach (const QString &filename, fileList) {
QFileInfo fileInfo(filename);
@@ -123,18 +98,20 @@ private slots:
}
}
- void iDontWantAnyStat() {
- QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
- testdir.setSorting(QDir::Unsorted);
- testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
+ void iDontWantAnyStat()
+ {
QBENCHMARK {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ testdir.setSorting(QDir::Unsorted);
+ testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted);
foreach (const QString &filename, fileList) {
Q_UNUSED(filename);
}
}
}
- void iDontWantAnyStatIterator() {
+ void iDontWantAnyStatIterator()
+ {
QBENCHMARK {
QDirIterator dit(QDir::tempPath() + QLatin1String("/test_speed"));
while (dit.hasNext()) {
@@ -143,11 +120,12 @@ private slots:
}
}
- void sorted_byTime() {
- QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
- testdir.setSorting(QDir::Time);
- testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
+ void sorted_byTime()
+ {
QBENCHMARK {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ testdir.setSorting(QDir::Time);
+ testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Time);
foreach (const QString &filename, fileList) {
Q_UNUSED(filename);
@@ -155,7 +133,17 @@ private slots:
}
}
- void sizeSpeedWithoutFilterLowLevel() {
+ void sorted_byName()
+ {
+ QBENCHMARK {
+ QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
+ testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
+ [[maybe_unused]] auto r = testdir.entryInfoList(QDir::NoFilter, QDir::Name);
+ }
+ }
+
+ void sizeSpeedWithoutFilterLowLevel()
+ {
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
#ifdef Q_OS_WIN
const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16();
@@ -163,22 +151,22 @@ private slots:
wcscpy(appendedPath, dirpath);
wcscat(appendedPath, L"\\*");
- WIN32_FIND_DATA fd;
- HANDLE hSearch = FindFirstFileW(appendedPath, &fd);
- QVERIFY(hSearch != INVALID_HANDLE_VALUE);
-
QBENCHMARK {
+ WIN32_FIND_DATA fd;
+ HANDLE hSearch = FindFirstFileW(appendedPath, &fd);
+ QVERIFY(hSearch != INVALID_HANDLE_VALUE);
+
do {
} while (FindNextFile(hSearch, &fd));
+ FindClose(hSearch);
}
- FindClose(hSearch);
#else
- DIR *dir = opendir(qPrintable(testdir.absolutePath()));
- QVERIFY(dir);
-
QVERIFY(!chdir(qPrintable(testdir.absolutePath())));
QBENCHMARK {
+ DIR *dir = opendir(qPrintable(testdir.absolutePath()));
+ QVERIFY(dir);
+
struct dirent *item = readdir(dir);
while (item) {
char *fileName = item->d_name;
@@ -188,11 +176,12 @@ private slots:
item = readdir(dir);
}
+ closedir(dir);
}
- closedir(dir);
#endif
}
};
-QTEST_MAIN(bench_QDir_10000)
-#include "bench_qdir_10000.moc"
+QTEST_MAIN(tst_QDir_10000)
+
+#include "tst_bench_qdir_10000.moc"
diff --git a/tests/benchmarks/corelib/io/qdir/CMakeLists.txt b/tests/benchmarks/corelib/io/qdir/CMakeLists.txt
index 10185014fa..f1800fc0cd 100644
--- a/tests/benchmarks/corelib/io/qdir/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qdir/CMakeLists.txt
@@ -1,3 +1,2 @@
-# Generated from qdir.pro.
-
add_subdirectory(10000)
+add_subdirectory(tree)
diff --git a/tests/benchmarks/corelib/io/qdir/tree/4.6.0-list.txt b/tests/benchmarks/corelib/io/qdir/tree/4.6.0-list.txt
index ee5f7eabc1..6f1a208fe0 100644
--- a/tests/benchmarks/corelib/io/qdir/tree/4.6.0-list.txt
+++ b/tests/benchmarks/corelib/io/qdir/tree/4.6.0-list.txt
@@ -7983,8 +7983,6 @@
qeventloop.cpp
qeventloop.h
qfunctions_p.h
- qfunctions_vxworks.cpp
- qfunctions_vxworks.h
qfunctions_wince.cpp
qfunctions_wince.h
qguard_p.h
diff --git a/tests/benchmarks/corelib/io/qdir/tree/CMakeLists.txt b/tests/benchmarks/corelib/io/qdir/tree/CMakeLists.txt
index c60bfcfdc3..f60c108480 100644
--- a/tests/benchmarks/corelib/io/qdir/tree/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qdir/tree/CMakeLists.txt
@@ -1,28 +1,25 @@
-# Generated from tree.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
-## bench_qdir_tree Binary:
+## tst_bench_qdir_tree Binary:
#####################################################################
-qt_internal_add_benchmark(bench_qdir_tree
+qt_internal_add_benchmark(tst_bench_qdir_tree
SOURCES
- bench_qdir_tree.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qdir_tree.cpp
+ LIBRARIES
Qt::Test
)
# Resources:
-set(bench_qdir_tree_resource_files
+set(qdir_tree_resource_files
"4.6.0-list.txt"
)
-qt_internal_add_resource(bench_qdir_tree "bench_qdir_tree"
+qt_internal_add_resource(tst_bench_qdir_tree "tst_bench_qdir_tree"
PREFIX
"/"
FILES
- ${bench_qdir_tree_resource_files}
+ ${qdir_tree_resource_files}
)
-
-
-#### Keys ignored in scope 1:.:.:tree.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.cpp
index 0abf8769a6..4f122c876c 100644
--- a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.cpp
+++ b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.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 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$
-**
-****************************************************************************/
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QtTest/QTest>
@@ -35,14 +10,14 @@
#include "../../../../../shared/filesystem.h"
-class bench_QDir_tree
+class tst_QDir_tree
: public QObject
{
Q_OBJECT
public:
- bench_QDir_tree()
- : prefix("./test-tree/"),
+ tst_QDir_tree()
+ : prefix("test-tree/"),
musicprefix(QLatin1String("music")),
photoprefix(QLatin1String("photos")),
sourceprefix(QLatin1String("source")),
@@ -60,6 +35,7 @@ private:
qint64 musicsize;
qint64 photosize;
qint64 sourcesize;
+ FileSystem fs; // Uses QTemporaryDir to tidy away file tree created.
private slots:
void initTestCase()
@@ -71,7 +47,7 @@ private slots:
QStack<QByteArray> stack;
QByteArray line;
- Q_FOREVER {
+ while (true) {
char ch;
if (!list.getChar(&ch))
break;
@@ -89,12 +65,11 @@ private slots:
--pop;
}
- line = list.readLine();
- line.chop(1);
+ line = list.readLine().trimmed();
stack.push(line);
line = prefix;
- Q_FOREACH(const QByteArray &pathElement, stack)
+ for (const QByteArray &pathElement : std::as_const(stack))
line += pathElement;
if (line.endsWith('/'))
@@ -140,13 +115,11 @@ private slots:
QTest::addColumn<int>("filter");
QTest::addColumn<int>("entryCount");
- QTest::newRow("*.cpp") << QStringList("*.cpp")
- << int(QDir::Files)
- << 3813;
-
- QTest::newRow("executables") << QStringList("*")
+ QTest::newRow("*.cpp") << QStringList("*.cpp") << int(QDir::Files) << 3791;
+ QTest::newRow("executables")
+ << QStringList("*")
<< int(QDir::Executable | QDir::Files | QDir::AllDirs | QDir::NoDotAndDotDot)
- << 543;
+ << 536;
}
void fileSearch() const
@@ -158,8 +131,9 @@ private slots:
int count = 0;
QBENCHMARK {
// Recursive directory iteration
- QDirIterator iterator(prefix, nameFilters, QDir::Filter(filter),
- QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
+ QDirIterator iterator(fs.absoluteFilePath(prefix),
+ nameFilters, QDir::Filter(filter),
+ QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
count = 0;
while (iterator.hasNext()) {
@@ -177,7 +151,8 @@ private slots:
{
int count = 0;
QBENCHMARK {
- QDirIterator iterator(prefix,
+ QDirIterator iterator(
+ fs.absoluteFilePath(prefix),
QDir::AllEntries | QDir::NoDotAndDotDot | QDir::Hidden | QDir::System,
QDirIterator::Subdirectories | QDirIterator::FollowSymlinks);
@@ -187,10 +162,10 @@ private slots:
++count;
}
- QCOMPARE(count, 11963);
+ QCOMPARE(count, 11906);
}
- QCOMPARE(count, 11963);
+ QCOMPARE(count, 11906);
}
void thousandFiles_data() const
@@ -209,19 +184,18 @@ private slots:
QBENCHMARK {
qint64 totalsize = 0;
int count = 0;
- QDirIterator iter(dirName, QDir::Files, QDirIterator::Subdirectories);
+ QDirIterator iter(fs.absoluteFilePath(dirName),
+ QDir::Files, QDirIterator::Subdirectories);
while(iter.hasNext()) {
- iter.next();
count++;
- totalsize += iter.fileInfo().size();
+ totalsize += iter.nextFileInfo().size();
}
QCOMPARE(count, 1000);
QCOMPARE(totalsize, expectedSize);
}
}
-private:
- FileSystem fs;
};
-QTEST_MAIN(bench_QDir_tree)
-#include "bench_qdir_tree.moc"
+QTEST_MAIN(tst_QDir_tree)
+
+#include "tst_bench_qdir_tree.moc"
diff --git a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.qrc b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.qrc
index d57cb6c368..d57cb6c368 100644
--- a/tests/benchmarks/corelib/io/qdir/tree/bench_qdir_tree.qrc
+++ b/tests/benchmarks/corelib/io/qdir/tree/tst_bench_qdir_tree.qrc
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/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"
diff --git a/tests/benchmarks/corelib/io/qfile/CMakeLists.txt b/tests/benchmarks/corelib/io/qfile/CMakeLists.txt
index 6ae5029a8a..0cd6b5fb16 100644
--- a/tests/benchmarks/corelib/io/qfile/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qfile/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qfile.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qfile Binary:
@@ -6,15 +7,12 @@
qt_internal_add_benchmark(tst_bench_qfile
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qfile.cpp
+ LIBRARIES
Qt::CorePrivate
Qt::Test
)
-#### Keys ignored in scope 1:.:.:qfile.pro:<TRUE>:
-# TEMPLATE = "app"
-
## Scopes:
#####################################################################
diff --git a/tests/benchmarks/corelib/io/qfile/main.cpp b/tests/benchmarks/corelib/io/qfile/main.cpp
deleted file mode 100644
index 73b3ba8c48..0000000000
--- a/tests/benchmarks/corelib/io/qfile/main.cpp
+++ /dev/null
@@ -1,707 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-#include <QDebug>
-#include <QTemporaryFile>
-#include <QString>
-#include <QDirIterator>
-
-#include <private/qfsfileengine_p.h>
-
-#include <qtest.h>
-
-#include <stdio.h>
-
-#ifdef Q_OS_WIN
-# include <windows.h>
-#endif
-
-#if defined(Q_OS_QNX) && defined(open)
-#undef open
-#endif
-
-#define BUFSIZE 1024*512
-#define FACTOR 1024*512
-#define TF_SIZE FACTOR*81
-
-// 10 predefined (but random() seek positions
-// hardcoded to be comparable over several runs
-const int seekpos[] = {int(TF_SIZE*0.52),
- int(TF_SIZE*0.23),
- int(TF_SIZE*0.73),
- int(TF_SIZE*0.77),
- int(TF_SIZE*0.80),
- int(TF_SIZE*0.12),
- int(TF_SIZE*0.53),
- int(TF_SIZE*0.21),
- int(TF_SIZE*0.27),
- int(TF_SIZE*0.78)};
-
-const int sp_size = sizeof(seekpos)/sizeof(int);
-
-class tst_qfile: public QObject
-{
-Q_ENUMS(BenchmarkType)
-Q_OBJECT
-public:
- enum BenchmarkType {
- QFileBenchmark = 1,
-#ifdef QT_BUILD_INTERNAL
- QFSFileEngineBenchmark,
-#endif
- Win32Benchmark,
- PosixBenchmark,
- QFileFromPosixBenchmark
- };
-private slots:
- void initTestCase();
- void cleanupTestCase();
-
- void open_data();
- void open();
- void seek_data();
- void seek();
-
- void readSmallFiles_QFile();
- void readSmallFiles_QFSFileEngine();
- void readSmallFiles_posix();
- void readSmallFiles_Win32();
-
- void readSmallFiles_QFile_data();
- void readSmallFiles_QFSFileEngine_data();
- void readSmallFiles_posix_data();
- void readSmallFiles_Win32_data();
-
- void readBigFile_QFile_data();
- void readBigFile_QFSFileEngine_data();
- void readBigFile_posix_data();
- void readBigFile_Win32_data();
-
- void readBigFile_QFile();
- void readBigFile_QFSFileEngine();
- void readBigFile_posix();
- void readBigFile_Win32();
-
-private:
- void readBigFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b);
- void readBigFile();
- void readSmallFiles_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b);
- void readSmallFiles();
- void createFile();
- void fillFile(int factor=FACTOR);
- void removeFile();
- void createSmallFiles();
- void removeSmallFiles();
- QString filename;
- QString tmpDirName;
-};
-
-Q_DECLARE_METATYPE(tst_qfile::BenchmarkType)
-Q_DECLARE_METATYPE(QIODevice::OpenMode)
-Q_DECLARE_METATYPE(QIODevice::OpenModeFlag)
-
-void tst_qfile::createFile()
-{
- removeFile(); // Cleanup in case previous test case aborted before cleaning up
-
- QTemporaryFile tmpFile;
- tmpFile.setAutoRemove(false);
- if (!tmpFile.open())
- ::exit(1);
- filename = tmpFile.fileName();
- tmpFile.close();
-}
-
-void tst_qfile::removeFile()
-{
- if (!filename.isEmpty())
- QFile::remove(filename);
-}
-
-void tst_qfile::fillFile(int factor)
-{
- QFile tmpFile(filename);
- tmpFile.open(QIODevice::WriteOnly);
- //for (int row=0; row<factor; ++row) {
- // tmpFile.write(QByteArray().fill('0'+row%('0'-'z'), 80));
- // tmpFile.write("\n");
- //}
- tmpFile.seek(factor*80);
- tmpFile.putChar('\n');
- tmpFile.close();
- // let IO settle
- QTest::qSleep(2000);
-}
-
-void tst_qfile::initTestCase()
-{
-}
-
-void tst_qfile::cleanupTestCase()
-{
-}
-
-void tst_qfile::readBigFile_QFile() { readBigFile(); }
-void tst_qfile::readBigFile_QFSFileEngine()
-{
-#ifdef QT_BUILD_INTERNAL
- readBigFile();
-#else
- QSKIP("This test requires -developer-build.");
-#endif
-}
-void tst_qfile::readBigFile_posix()
-{
- readBigFile();
-}
-void tst_qfile::readBigFile_Win32() { readBigFile(); }
-
-void tst_qfile::readBigFile_QFile_data()
-{
- readBigFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
- readBigFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered);
- readBigFile_data(QFileBenchmark, QIODevice::Text, QIODevice::NotOpen);
- readBigFile_data(QFileBenchmark, QIODevice::Text, QIODevice::Unbuffered);
-
-}
-
-void tst_qfile::readBigFile_QFSFileEngine_data()
-{
-#ifdef QT_BUILD_INTERNAL
- readBigFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
- readBigFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered);
- readBigFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::NotOpen);
- readBigFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered);
-#else
- QTest::addColumn<int>("dummy");
- QTest::newRow("Test will be skipped") << -1;
-#endif
-}
-
-void tst_qfile::readBigFile_posix_data()
-{
- readBigFile_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
-}
-
-void tst_qfile::readBigFile_Win32_data()
-{
- readBigFile_data(Win32Benchmark, QIODevice::NotOpen, QIODevice::NotOpen);
-}
-
-
-void tst_qfile::readBigFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b)
-{
- QTest::addColumn<tst_qfile::BenchmarkType>("testType");
- QTest::addColumn<int>("blockSize");
- QTest::addColumn<QFile::OpenModeFlag>("textMode");
- QTest::addColumn<QFile::OpenModeFlag>("bufferedMode");
-
- const int bs[] = {1024, 1024*2, 1024*8, 1024*16, 1024*32,1024*512};
- int bs_entries = sizeof(bs)/sizeof(const int);
-
- QString flagstring;
- if (t & QIODevice::Text) flagstring += "textMode ";
- if (b & QIODevice::Unbuffered) flagstring += "unbuffered ";
- if (flagstring.isEmpty()) flagstring = "none";
-
- for (int i=0; i<bs_entries; ++i)
- QTest::newRow((QString("BS: %1, Flags: %2" )).arg(bs[i]).arg(flagstring).toLatin1().constData()) << type << bs[i] << t << b;
-}
-
-void tst_qfile::readBigFile()
-{
- QFETCH(tst_qfile::BenchmarkType, testType);
- QFETCH(int, blockSize);
- QFETCH(QFile::OpenModeFlag, textMode);
- QFETCH(QFile::OpenModeFlag, bufferedMode);
-
-#ifndef Q_OS_WIN
- if (testType == Win32Benchmark)
- QSKIP("This is Windows only benchmark.");
-#endif
-
- char *buffer = new char[BUFSIZE];
- createFile();
- fillFile();
-
- switch (testType) {
- case(QFileBenchmark): {
- QFile file(filename);
- file.open(QIODevice::ReadOnly|textMode|bufferedMode);
- QBENCHMARK {
- while(!file.atEnd())
- file.read(blockSize);
- file.reset();
- }
- file.close();
- }
- break;
-#ifdef QT_BUILD_INTERNAL
- case(QFSFileEngineBenchmark): {
- QFSFileEngine fse(filename);
- fse.open(QIODevice::ReadOnly|textMode|bufferedMode);
- QBENCHMARK {
- //qWarning() << fse.supportsExtension(QAbstractFileEngine::AtEndExtension);
- while(fse.read(buffer, blockSize));
- fse.seek(0);
- }
- fse.close();
- }
- break;
-#endif
- case(PosixBenchmark): {
- QByteArray data = filename.toLocal8Bit();
- const char* cfilename = data.constData();
- FILE* cfile = ::fopen(cfilename, "rb");
- QBENCHMARK {
- while(!feof(cfile))
- ::fread(buffer, blockSize, 1, cfile);
- ::fseek(cfile, 0, SEEK_SET);
- }
- ::fclose(cfile);
- }
- break;
- case(QFileFromPosixBenchmark): {
- // No gain in benchmarking this case
- }
- break;
- case(Win32Benchmark): {
-#ifdef Q_OS_WIN
- HANDLE hndl;
-
- // ensure we don't account string conversion
- wchar_t* cfilename = (wchar_t*)filename.utf16();
-
- hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
- Q_ASSERT(hndl);
- wchar_t* nativeBuffer = new wchar_t[BUFSIZE];
- DWORD numberOfBytesRead;
-
- QBENCHMARK {
- do {
- ReadFile(hndl, nativeBuffer, blockSize, &numberOfBytesRead, NULL);
- } while(numberOfBytesRead != 0);
- SetFilePointer(hndl, 0, NULL, FILE_BEGIN);
- }
- delete[] nativeBuffer;
- CloseHandle(hndl);
-#else
- QFAIL("Not running on a non-Windows platform!");
-#endif
- }
- break;
- }
-
- removeFile();
- delete[] buffer;
-}
-
-void tst_qfile::seek_data()
-{
- QTest::addColumn<tst_qfile::BenchmarkType>("testType");
- QTest::newRow("QFile") << QFileBenchmark;
-#ifdef QT_BUILD_INTERNAL
- QTest::newRow("QFSFileEngine") << QFSFileEngineBenchmark;
-#endif
- QTest::newRow("Posix FILE*") << PosixBenchmark;
-#ifdef Q_OS_WIN
- QTest::newRow("Win32 API") << Win32Benchmark;
-#endif
-}
-
-void tst_qfile::seek()
-{
- QFETCH(tst_qfile::BenchmarkType, testType);
- int i = 0;
-
- createFile();
- fillFile();
-
- switch (testType) {
- case(QFileBenchmark): {
- QFile file(filename);
- file.open(QIODevice::ReadOnly);
- QBENCHMARK {
- i=(i+1)%sp_size;
- file.seek(seekpos[i]);
- }
- file.close();
- }
- break;
-#ifdef QT_BUILD_INTERNAL
- case(QFSFileEngineBenchmark): {
- QFSFileEngine fse(filename);
- fse.open(QIODevice::ReadOnly);
- QBENCHMARK {
- i=(i+1)%sp_size;
- fse.seek(seekpos[i]);
- }
- fse.close();
- }
- break;
-#endif
- case(PosixBenchmark): {
- QByteArray data = filename.toLocal8Bit();
- const char* cfilename = data.constData();
- FILE* cfile = ::fopen(cfilename, "rb");
- QBENCHMARK {
- i=(i+1)%sp_size;
- ::fseek(cfile, seekpos[i], SEEK_SET);
- }
- ::fclose(cfile);
- }
- break;
- case(QFileFromPosixBenchmark): {
- // No gain in benchmarking this case
- }
- break;
- case(Win32Benchmark): {
-#ifdef Q_OS_WIN
- HANDLE hndl;
-
- // ensure we don't account string conversion
- wchar_t* cfilename = (wchar_t*)filename.utf16();
-
- hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
- Q_ASSERT(hndl);
- QBENCHMARK {
- i=(i+1)%sp_size;
- SetFilePointer(hndl, seekpos[i], NULL, 0);
- }
- CloseHandle(hndl);
-#else
- QFAIL("Not running on a Windows plattform!");
-#endif
- }
- break;
- }
-
- removeFile();
-}
-
-void tst_qfile::open_data()
-{
- QTest::addColumn<tst_qfile::BenchmarkType>("testType");
- QTest::newRow("QFile") << QFileBenchmark;
-#ifdef QT_BUILD_INTERNAL
- QTest::newRow("QFSFileEngine") << QFSFileEngineBenchmark;
-#endif
- QTest::newRow("Posix FILE*") << PosixBenchmark;
- QTest::newRow("QFile from FILE*") << QFileFromPosixBenchmark;
-#ifdef Q_OS_WIN
- QTest::newRow("Win32 API") << Win32Benchmark;
-#endif
-}
-
-void tst_qfile::open()
-{
- QFETCH(tst_qfile::BenchmarkType, testType);
-
- createFile();
-
- switch (testType) {
- case(QFileBenchmark): {
- QBENCHMARK {
- QFile file( filename );
- file.open( QIODevice::ReadOnly );
- file.close();
- }
- }
- break;
-#ifdef QT_BUILD_INTERNAL
- case(QFSFileEngineBenchmark): {
- QBENCHMARK {
- QFSFileEngine fse(filename);
- fse.open(QIODevice::ReadOnly);
- fse.close();
- }
- }
- break;
-#endif
- case(PosixBenchmark): {
- // ensure we don't account toLocal8Bit()
- QByteArray data = filename.toLocal8Bit();
- const char* cfilename = data.constData();
-
- QBENCHMARK {
- FILE* cfile = ::fopen(cfilename, "rb");
- ::fclose(cfile);
- }
- }
- break;
- case(QFileFromPosixBenchmark): {
- // ensure we don't account toLocal8Bit()
- QByteArray data = filename.toLocal8Bit();
- const char* cfilename = data.constData();
- FILE* cfile = ::fopen(cfilename, "rb");
-
- QBENCHMARK {
- QFile file;
- file.open(cfile, QIODevice::ReadOnly);
- file.close();
- }
- ::fclose(cfile);
- }
- break;
- case(Win32Benchmark): {
-#ifdef Q_OS_WIN
- HANDLE hndl;
-
- // ensure we don't account string conversion
- wchar_t* cfilename = (wchar_t*)filename.utf16();
-
- QBENCHMARK {
- hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
- Q_ASSERT(hndl);
- CloseHandle(hndl);
- }
-#else
- QFAIL("Not running on a non-Windows platform!");
-#endif
- }
- break;
- }
-
- removeFile();
-}
-
-
-void tst_qfile::readSmallFiles_QFile() { readSmallFiles(); }
-void tst_qfile::readSmallFiles_QFSFileEngine()
-{
-#ifdef QT_BUILD_INTERNAL
- readSmallFiles();
-#else
- QSKIP("This test requires -developer-build.");
-#endif
-}
-void tst_qfile::readSmallFiles_posix()
-{
- readSmallFiles();
-}
-void tst_qfile::readSmallFiles_Win32()
-{
- readSmallFiles();
-}
-
-void tst_qfile::readSmallFiles_QFile_data()
-{
- readSmallFiles_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
- readSmallFiles_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered);
- readSmallFiles_data(QFileBenchmark, QIODevice::Text, QIODevice::NotOpen);
- readSmallFiles_data(QFileBenchmark, QIODevice::Text, QIODevice::Unbuffered);
-
-}
-
-void tst_qfile::readSmallFiles_QFSFileEngine_data()
-{
-#ifdef QT_BUILD_INTERNAL
- readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
- readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered);
- readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::NotOpen);
- readSmallFiles_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered);
-#else
- QTest::addColumn<int>("dummy");
- QTest::newRow("Test will be skipped") << -1;
-#endif
-}
-
-void tst_qfile::readSmallFiles_posix_data()
-{
- readSmallFiles_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
-}
-
-void tst_qfile::readSmallFiles_Win32_data()
-{
- readSmallFiles_data(Win32Benchmark, QIODevice::NotOpen, QIODevice::NotOpen);
-}
-
-
-void tst_qfile::readSmallFiles_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b)
-{
- QTest::addColumn<tst_qfile::BenchmarkType>("testType");
- QTest::addColumn<int>("blockSize");
- QTest::addColumn<QFile::OpenModeFlag>("textMode");
- QTest::addColumn<QFile::OpenModeFlag>("bufferedMode");
-
- const int bs[] = {1024, 1024*2, 1024*8, 1024*16, 1024*32,1024*512};
- int bs_entries = sizeof(bs)/sizeof(const int);
-
- QString flagstring;
- if (t & QIODevice::Text) flagstring += "textMode ";
- if (b & QIODevice::Unbuffered) flagstring += "unbuffered ";
- if (flagstring.isEmpty()) flagstring = "none";
-
- for (int i=0; i<bs_entries; ++i)
- QTest::newRow((QString("BS: %1, Flags: %2" )).arg(bs[i]).arg(flagstring).toLatin1().constData()) << type << bs[i] << t << b;
-
-}
-
-void tst_qfile::createSmallFiles()
-{
- QDir dir = QDir::temp();
- dir.mkdir("tst");
- dir.cd("tst");
- tmpDirName = dir.absolutePath();
-
- for (int i = 0; i < 1000; ++i) {
- QFile f(tmpDirName + QLatin1Char('/') + QString::number(i));
- f.open(QIODevice::WriteOnly);
- f.seek(511);
- f.putChar('\n');
- f.close();
- }
-}
-
-void tst_qfile::removeSmallFiles()
-{
- QDirIterator it(tmpDirName, QDirIterator::FollowSymlinks);
- while (it.hasNext())
- QFile::remove(it.next());
- QDir::temp().rmdir("tst");
-}
-
-
-void tst_qfile::readSmallFiles()
-{
- QFETCH(tst_qfile::BenchmarkType, testType);
- QFETCH(int, blockSize);
- QFETCH(QFile::OpenModeFlag, textMode);
- QFETCH(QFile::OpenModeFlag, bufferedMode);
-
-#ifndef Q_OS_WIN
- if (testType == Win32Benchmark)
- QSKIP("This is Windows only benchmark.");
-#endif
-
- createSmallFiles();
-
- QDir dir(tmpDirName);
- const QStringList files = dir.entryList(QDir::NoDotAndDotDot|QDir::NoSymLinks|QDir::Files);
- char *buffer = new char[BUFSIZE];
-
- switch (testType) {
- case(QFileBenchmark): {
- QList<QFile*> fileList;
- Q_FOREACH(QString file, files) {
- QFile *f = new QFile(tmpDirName + QLatin1Char('/') + file);
- f->open(QIODevice::ReadOnly|textMode|bufferedMode);
- fileList.append(f);
- }
-
- QBENCHMARK {
- Q_FOREACH(QFile *file, fileList) {
- while (!file->atEnd()) {
- file->read(buffer, blockSize);
- }
- }
- }
-
- Q_FOREACH(QFile *file, fileList) {
- file->close();
- delete file;
- }
- }
- break;
-#ifdef QT_BUILD_INTERNAL
- case(QFSFileEngineBenchmark): {
- QList<QFSFileEngine*> fileList;
- Q_FOREACH(QString file, files) {
- QFSFileEngine *fse = new QFSFileEngine(tmpDirName + QLatin1Char('/') + file);
- fse->open(QIODevice::ReadOnly|textMode|bufferedMode);
- fileList.append(fse);
- }
-
- QBENCHMARK {
- Q_FOREACH(QFSFileEngine *fse, fileList) {
- while (fse->read(buffer, blockSize));
- }
- }
-
- Q_FOREACH(QFSFileEngine *fse, fileList) {
- fse->close();
- delete fse;
- }
- }
- break;
-#endif
- case(PosixBenchmark): {
- QList<FILE*> fileList;
- Q_FOREACH(QString file, files) {
- fileList.append(::fopen(QFile::encodeName(tmpDirName + QLatin1Char('/') + file).constData(), "rb"));
- }
-
- QBENCHMARK {
- Q_FOREACH(FILE* cfile, fileList) {
- while(!feof(cfile))
- ::fread(buffer, blockSize, 1, cfile);
- ::fseek(cfile, 0, SEEK_SET);
- }
- }
-
- Q_FOREACH(FILE* cfile, fileList) {
- ::fclose(cfile);
- }
- }
- break;
- case(QFileFromPosixBenchmark): {
- // No gain in benchmarking this case
- }
- break;
- case(Win32Benchmark): {
-#ifdef Q_OS_WIN
- HANDLE hndl;
-
- // ensure we don't account string conversion
- wchar_t* cfilename = (wchar_t*)filename.utf16();
-
- hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
- Q_ASSERT(hndl);
- wchar_t* nativeBuffer = new wchar_t[BUFSIZE];
- DWORD numberOfBytesRead;
- QBENCHMARK {
- do {
- ReadFile(hndl, nativeBuffer, blockSize, &numberOfBytesRead, NULL);
- } while(numberOfBytesRead != 0);
- }
- delete nativeBuffer;
- CloseHandle(hndl);
-#else
- QFAIL("Not running on a non-Windows platform!");
-#endif
- }
- break;
- }
-
- removeSmallFiles();
- delete[] buffer;
-}
-
-QTEST_MAIN(tst_qfile)
-
-#include "main.moc"
diff --git a/tests/benchmarks/corelib/io/qfile/tst_bench_qfile.cpp b/tests/benchmarks/corelib/io/qfile/tst_bench_qfile.cpp
new file mode 100644
index 0000000000..b805726f5f
--- /dev/null
+++ b/tests/benchmarks/corelib/io/qfile/tst_bench_qfile.cpp
@@ -0,0 +1,593 @@
+// Copyright (C) 2021 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+#include <QDebug>
+#include <QTemporaryFile>
+#include <QString>
+#include <QDirIterator>
+
+#include <private/qfsfileengine_p.h>
+
+#include <qtest.h>
+
+#include <stdio.h>
+
+#ifdef Q_OS_WIN
+# include <qt_windows.h>
+#endif
+
+#if defined(Q_OS_QNX) && defined(open)
+#undef open
+#endif
+
+#define BUFSIZE 1024*512
+#define FACTOR 1024*512
+#define TF_SIZE FACTOR*81
+
+// 10 predefined (but random() seek positions
+// hardcoded to be comparable over several runs
+const int seekpos[] = {int(TF_SIZE*0.52),
+ int(TF_SIZE*0.23),
+ int(TF_SIZE*0.73),
+ int(TF_SIZE*0.77),
+ int(TF_SIZE*0.80),
+ int(TF_SIZE*0.12),
+ int(TF_SIZE*0.53),
+ int(TF_SIZE*0.21),
+ int(TF_SIZE*0.27),
+ int(TF_SIZE*0.78)};
+
+const int sp_size = sizeof(seekpos)/sizeof(int);
+
+class tst_qfile: public QObject
+{
+Q_ENUMS(BenchmarkType)
+Q_OBJECT
+public:
+ enum BenchmarkType {
+ QFileBenchmark = 1,
+#ifdef QT_BUILD_INTERNAL
+ QFSFileEngineBenchmark,
+#endif
+ Win32Benchmark,
+ PosixBenchmark,
+ QFileFromPosixBenchmark
+ };
+private slots:
+ void initTestCase();
+
+ void open_data();
+ void open();
+ void seek_data();
+ void seek();
+
+ void readSmallFiles_QFile() { readSmallFiles(); }
+ void readSmallFiles_QFSFileEngine() { readSmallFiles(); }
+ void readSmallFiles_posix() { readSmallFiles(); }
+ void readSmallFiles_Win32() { readSmallFiles(); }
+
+ void readSmallFiles_QFile_data();
+ void readSmallFiles_QFSFileEngine_data();
+ void readSmallFiles_posix_data();
+ void readSmallFiles_Win32_data();
+
+ void readBigFile_QFile_data();
+ void readBigFile_QFSFileEngine_data();
+ void readBigFile_posix_data();
+ void readBigFile_Win32_data();
+
+ void readBigFile_QFile() { readBigFile(); }
+ void readBigFile_QFSFileEngine() { readBigFile(); }
+ void readBigFile_posix() { readBigFile(); }
+ void readBigFile_Win32() { readBigFile(); }
+
+private:
+ void readFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b);
+ void readBigFile();
+ void readSmallFiles();
+
+ class TestDataDir : public QTemporaryDir
+ {
+ void createFile();
+ void createSmallFiles();
+ public:
+ TestDataDir() : QTemporaryDir(), fail(errorString().toLocal8Bit())
+ {
+ if (fail.isEmpty() && !QTemporaryDir::isValid())
+ fail = "Failed to create temporary directory for data";
+ if (isValid())
+ createSmallFiles();
+ if (isValid())
+ createFile();
+ if (isValid())
+ QTest::qSleep(2000); // let IO settle
+ }
+ bool isValid() { return QTemporaryDir::isValid() && fail.isEmpty(); }
+ QByteArray fail;
+ QString filename;
+ } tempDir;
+};
+
+Q_DECLARE_METATYPE(tst_qfile::BenchmarkType)
+Q_DECLARE_METATYPE(QIODevice::OpenMode)
+Q_DECLARE_METATYPE(QIODevice::OpenModeFlag)
+
+/* None of the tests modify the test data in tempDir, so it's OK to only create
+ * and tear down the directory once.
+ */
+void tst_qfile::TestDataDir::createFile()
+{
+ QFile tmpFile(filePath("testFile"));
+ if (!tmpFile.open(QIODevice::WriteOnly)) {
+ fail = "Unable to prepare files for test";
+ return;
+ }
+#if 0 // Varied data, rather than filling with '\0' bytes:
+ for (int row = 0; row < FACTOR; ++row) {
+ tmpFile.write(QByteArray().fill('0' + row % ('0' - 'z'), 80));
+ tmpFile.write("\n");
+ }
+#else
+ tmpFile.seek(FACTOR * 80);
+ tmpFile.putChar('\n');
+#endif
+ filename = tmpFile.fileName();
+ tmpFile.close();
+}
+
+void tst_qfile::TestDataDir::createSmallFiles()
+{
+ for (int i = 0; i < 1000; ++i) {
+ QFile f(filePath(QString::number(i)));
+ if (!f.open(QIODevice::WriteOnly)) {
+ fail = "Unable to prepare small files for test";
+ return;
+ }
+ f.seek(511);
+ f.putChar('\n');
+ f.close();
+ }
+}
+
+void tst_qfile::initTestCase()
+{
+ QVERIFY2(tempDir.isValid(), tempDir.fail.constData());
+}
+
+void tst_qfile::readFile_data(BenchmarkType type, QIODevice::OpenModeFlag t,
+ QIODevice::OpenModeFlag b)
+{
+ QTest::addColumn<tst_qfile::BenchmarkType>("testType");
+ QTest::addColumn<int>("blockSize");
+ QTest::addColumn<QFile::OpenModeFlag>("textMode");
+ QTest::addColumn<QFile::OpenModeFlag>("bufferedMode");
+
+ QByteArray flagstring;
+ if (t & QIODevice::Text)
+ flagstring += "textMode";
+ if (b & QIODevice::Unbuffered) {
+ if (flagstring.size())
+ flagstring += ' ';
+ flagstring += "unbuffered";
+ }
+ if (flagstring.isEmpty())
+ flagstring = "none";
+
+ const int kbs[] = {1, 2, 8, 16, 32, 512};
+ for (int kb : kbs) {
+ const int size = 1024 * kb;
+ QTest::addRow("BS: %d, Flags: %s", size, flagstring.constData())
+ << type << size << t << b;
+ }
+}
+
+void tst_qfile::readBigFile_QFile_data()
+{
+ readFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
+ readFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered);
+ readFile_data(QFileBenchmark, QIODevice::Text, QIODevice::NotOpen);
+ readFile_data(QFileBenchmark, QIODevice::Text, QIODevice::Unbuffered);
+
+}
+
+void tst_qfile::readBigFile_QFSFileEngine_data()
+{
+#ifdef QT_BUILD_INTERNAL
+ // Support for buffering dropped at 5.10, so only test Unbuffered
+ readFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered);
+ readFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered);
+#else
+ QSKIP("This test requires -developer-build.");
+#endif
+}
+
+void tst_qfile::readBigFile_posix_data()
+{
+ readFile_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
+}
+
+void tst_qfile::readBigFile_Win32_data()
+{
+#ifdef Q_OS_WIN
+ readFile_data(Win32Benchmark, QIODevice::NotOpen, QIODevice::NotOpen);
+#else
+ QSKIP("This is Windows only benchmark.");
+#endif
+}
+
+void tst_qfile::readBigFile()
+{
+ QFETCH(tst_qfile::BenchmarkType, testType);
+ QFETCH(int, blockSize);
+ QFETCH(QFile::OpenModeFlag, textMode);
+ QFETCH(QFile::OpenModeFlag, bufferedMode);
+
+ char buffer[BUFSIZE];
+ switch (testType) {
+ case QFileBenchmark: {
+ QFile file(tempDir.filename);
+ file.open(QIODevice::ReadOnly|textMode|bufferedMode);
+ QBENCHMARK {
+ while(!file.atEnd())
+ file.read(blockSize);
+ file.reset();
+ }
+ file.close();
+ }
+ break;
+#ifdef QT_BUILD_INTERNAL
+ case QFSFileEngineBenchmark: {
+ QFSFileEngine fse(tempDir.filename);
+ fse.open(QIODevice::ReadOnly | textMode | bufferedMode, std::nullopt);
+ QBENCHMARK {
+ //qWarning() << fse.supportsExtension(QAbstractFileEngine::AtEndExtension);
+ while (fse.read(buffer, blockSize)) {}
+ fse.seek(0);
+ }
+ fse.close();
+ }
+ break;
+#endif
+ case PosixBenchmark: {
+ QByteArray data = tempDir.filename.toLocal8Bit();
+ const char* cfilename = data.constData();
+ FILE* cfile = ::fopen(cfilename, "rb");
+ QBENCHMARK {
+ while(!feof(cfile))
+ [[maybe_unused]] auto r = ::fread(buffer, blockSize, 1, cfile);
+ ::fseek(cfile, 0, SEEK_SET);
+ }
+ ::fclose(cfile);
+ }
+ break;
+ case QFileFromPosixBenchmark: {
+ // No gain in benchmarking this case
+ }
+ break;
+ case Win32Benchmark: {
+#ifdef Q_OS_WIN
+ HANDLE hndl;
+
+ // ensure we don't account string conversion
+ const wchar_t *cfilename = reinterpret_cast<const wchar_t *>(tempDir.filename.utf16());
+
+ hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
+ Q_ASSERT(hndl);
+ wchar_t* nativeBuffer = new wchar_t[BUFSIZE];
+ DWORD numberOfBytesRead;
+
+ QBENCHMARK {
+ do {
+ ReadFile(hndl, nativeBuffer, blockSize, &numberOfBytesRead, NULL);
+ } while(numberOfBytesRead != 0);
+ SetFilePointer(hndl, 0, NULL, FILE_BEGIN);
+ }
+ delete[] nativeBuffer;
+ CloseHandle(hndl);
+#else
+ QFAIL("Not running on a non-Windows platform!");
+#endif
+ }
+ break;
+ }
+}
+
+void tst_qfile::seek_data()
+{
+ QTest::addColumn<tst_qfile::BenchmarkType>("testType");
+ QTest::newRow("QFile") << QFileBenchmark;
+#ifdef QT_BUILD_INTERNAL
+ QTest::newRow("QFSFileEngine") << QFSFileEngineBenchmark;
+#endif
+ QTest::newRow("Posix FILE*") << PosixBenchmark;
+#ifdef Q_OS_WIN
+ QTest::newRow("Win32 API") << Win32Benchmark;
+#endif
+}
+
+void tst_qfile::seek()
+{
+ QFETCH(tst_qfile::BenchmarkType, testType);
+ int i = 0;
+
+ switch (testType) {
+ case QFileBenchmark: {
+ QFile file(tempDir.filename);
+ file.open(QIODevice::ReadOnly);
+ QBENCHMARK {
+ i=(i+1)%sp_size;
+ file.seek(seekpos[i]);
+ }
+ file.close();
+ }
+ break;
+#ifdef QT_BUILD_INTERNAL
+ case QFSFileEngineBenchmark: {
+ QFSFileEngine fse(tempDir.filename);
+ fse.open(QIODevice::ReadOnly | QIODevice::Unbuffered, std::nullopt);
+ QBENCHMARK {
+ i=(i+1)%sp_size;
+ fse.seek(seekpos[i]);
+ }
+ fse.close();
+ }
+ break;
+#endif
+ case PosixBenchmark: {
+ QByteArray data = tempDir.filename.toLocal8Bit();
+ const char* cfilename = data.constData();
+ FILE* cfile = ::fopen(cfilename, "rb");
+ QBENCHMARK {
+ i=(i+1)%sp_size;
+ ::fseek(cfile, seekpos[i], SEEK_SET);
+ }
+ ::fclose(cfile);
+ }
+ break;
+ case QFileFromPosixBenchmark: {
+ // No gain in benchmarking this case
+ }
+ break;
+ case Win32Benchmark: {
+#ifdef Q_OS_WIN
+ HANDLE hndl;
+
+ // ensure we don't account string conversion
+ const wchar_t *cfilename = reinterpret_cast<const wchar_t *>(tempDir.filename.utf16());
+
+ hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
+ Q_ASSERT(hndl);
+ QBENCHMARK {
+ i=(i+1)%sp_size;
+ SetFilePointer(hndl, seekpos[i], NULL, 0);
+ }
+ CloseHandle(hndl);
+#else
+ QFAIL("Not running on a Windows platform!");
+#endif
+ }
+ break;
+ }
+}
+
+void tst_qfile::open_data()
+{
+ QTest::addColumn<tst_qfile::BenchmarkType>("testType");
+ QTest::newRow("QFile") << QFileBenchmark;
+#ifdef QT_BUILD_INTERNAL
+ QTest::newRow("QFSFileEngine") << QFSFileEngineBenchmark;
+#endif
+ QTest::newRow("Posix FILE*") << PosixBenchmark;
+ QTest::newRow("QFile from FILE*") << QFileFromPosixBenchmark;
+#ifdef Q_OS_WIN
+ QTest::newRow("Win32 API") << Win32Benchmark;
+#endif
+}
+
+void tst_qfile::open()
+{
+ QFETCH(tst_qfile::BenchmarkType, testType);
+
+ switch (testType) {
+ case QFileBenchmark: {
+ QBENCHMARK {
+ QFile file(tempDir.filename);
+ file.open(QIODevice::ReadOnly);
+ file.close();
+ }
+ }
+ break;
+#ifdef QT_BUILD_INTERNAL
+ case QFSFileEngineBenchmark: {
+ QBENCHMARK {
+ QFSFileEngine fse(tempDir.filename);
+ fse.open(QIODevice::ReadOnly | QIODevice::Unbuffered, std::nullopt);
+ fse.close();
+ }
+ }
+ break;
+#endif
+ case PosixBenchmark: {
+ // ensure we don't account toLocal8Bit()
+ QByteArray data = tempDir.filename.toLocal8Bit();
+ const char* cfilename = data.constData();
+
+ QBENCHMARK {
+ FILE* cfile = ::fopen(cfilename, "rb");
+ ::fclose(cfile);
+ }
+ }
+ break;
+ case QFileFromPosixBenchmark: {
+ // ensure we don't account toLocal8Bit()
+ QByteArray data = tempDir.filename.toLocal8Bit();
+ const char* cfilename = data.constData();
+ FILE* cfile = ::fopen(cfilename, "rb");
+
+ QBENCHMARK {
+ QFile file;
+ file.open(cfile, QIODevice::ReadOnly);
+ file.close();
+ }
+ ::fclose(cfile);
+ }
+ break;
+ case Win32Benchmark: {
+#ifdef Q_OS_WIN
+ HANDLE hndl;
+
+ // ensure we don't account string conversion
+ const wchar_t *cfilename = reinterpret_cast<const wchar_t *>(tempDir.filename.utf16());
+
+ QBENCHMARK {
+ hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
+ Q_ASSERT(hndl);
+ CloseHandle(hndl);
+ }
+#else
+ QFAIL("Not running on a non-Windows platform!");
+#endif
+ }
+ break;
+ }
+}
+
+void tst_qfile::readSmallFiles_QFile_data()
+{
+ readFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
+ readFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered);
+ readFile_data(QFileBenchmark, QIODevice::Text, QIODevice::NotOpen);
+ readFile_data(QFileBenchmark, QIODevice::Text, QIODevice::Unbuffered);
+
+}
+
+void tst_qfile::readSmallFiles_QFSFileEngine_data()
+{
+#ifdef QT_BUILD_INTERNAL
+ // Support for buffering dropped at 5.10, so only test Unbuffered
+ readFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered);
+ readFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered);
+#else
+ QSKIP("This test requires -developer-build.");
+#endif
+}
+
+void tst_qfile::readSmallFiles_posix_data()
+{
+ readFile_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen);
+}
+
+void tst_qfile::readSmallFiles_Win32_data()
+{
+
+#ifdef Q_OS_WIN
+ readFile_data(Win32Benchmark, QIODevice::NotOpen, QIODevice::NotOpen);
+#else
+ QSKIP("This is Windows only benchmark.");
+#endif
+}
+
+void tst_qfile::readSmallFiles()
+{
+ QFETCH(tst_qfile::BenchmarkType, testType);
+ QFETCH(int, blockSize);
+ QFETCH(QFile::OpenModeFlag, textMode);
+ QFETCH(QFile::OpenModeFlag, bufferedMode);
+
+ QDir dir(tempDir.path());
+ const QStringList files = dir.entryList(QDir::NoDotAndDotDot|QDir::NoSymLinks|QDir::Files);
+ char buffer[BUFSIZE];
+
+ switch (testType) {
+ case QFileBenchmark: {
+ QList<QFile*> fileList;
+ for (const QString &file : files) {
+ QFile *f = new QFile(tempDir.filePath(file));
+ f->open(QIODevice::ReadOnly|textMode|bufferedMode);
+ fileList.append(f);
+ }
+
+ QBENCHMARK {
+ for (QFile *const file : std::as_const(fileList)) {
+ while (!file->atEnd())
+ file->read(buffer, blockSize);
+ }
+ }
+
+ for (QFile *const file : std::as_const(fileList)) {
+ file->close();
+ delete file;
+ }
+ }
+ break;
+#ifdef QT_BUILD_INTERNAL
+ case QFSFileEngineBenchmark: {
+ QList<QFSFileEngine*> fileList;
+ for (const QString &file : files) {
+ QFSFileEngine *fse = new QFSFileEngine(tempDir.filePath(file));
+ fse->open(QIODevice::ReadOnly | textMode | bufferedMode, std::nullopt);
+ fileList.append(fse);
+ }
+
+ QBENCHMARK {
+ for (QFSFileEngine *const fse : std::as_const(fileList))
+ while (fse->read(buffer, blockSize)) {}
+ }
+
+ for (QFSFileEngine *const fse : std::as_const(fileList)) {
+ fse->close();
+ delete fse;
+ }
+ }
+ break;
+#endif
+ case PosixBenchmark: {
+ QList<FILE *> fileList;
+ for (const QString &file : files)
+ fileList.append(::fopen(QFile::encodeName(tempDir.filePath(file)).constData(), "rb"));
+
+ QBENCHMARK {
+ for (FILE *const cfile : std::as_const(fileList)) {
+ while (!feof(cfile))
+ [[maybe_unused]] auto f = ::fread(buffer, blockSize, 1, cfile);
+ ::fseek(cfile, 0, SEEK_SET);
+ }
+ }
+
+ for (FILE *const cfile : std::as_const(fileList))
+ ::fclose(cfile);
+ }
+ break;
+ case QFileFromPosixBenchmark: {
+ // No gain in benchmarking this case
+ }
+ break;
+ case Win32Benchmark: {
+#ifdef Q_OS_WIN
+ HANDLE hndl;
+
+ // ensure we don't account string conversion
+ const wchar_t *cfilename = reinterpret_cast<const wchar_t *>(tempDir.filename.utf16());
+
+ hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0);
+ Q_ASSERT(hndl);
+ wchar_t* nativeBuffer = new wchar_t[BUFSIZE];
+ DWORD numberOfBytesRead;
+ QBENCHMARK {
+ do {
+ ReadFile(hndl, nativeBuffer, blockSize, &numberOfBytesRead, NULL);
+ } while(numberOfBytesRead != 0);
+ }
+ delete nativeBuffer;
+ CloseHandle(hndl);
+#else
+ QFAIL("Not running on a non-Windows platform!");
+#endif
+ }
+ break;
+ }
+}
+
+QTEST_MAIN(tst_qfile)
+
+#include "tst_bench_qfile.moc"
diff --git a/tests/benchmarks/corelib/io/qfileinfo/CMakeLists.txt b/tests/benchmarks/corelib/io/qfileinfo/CMakeLists.txt
index 1c088bf71a..84a667ca7d 100644
--- a/tests/benchmarks/corelib/io/qfileinfo/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qfileinfo/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qfileinfo.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qfileinfo Binary:
@@ -6,11 +7,8 @@
qt_internal_add_benchmark(tst_bench_qfileinfo
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qfileinfo.cpp
+ LIBRARIES
Qt::CorePrivate
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qfileinfo.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/corelib/io/qfileinfo/main.cpp b/tests/benchmarks/corelib/io/qfileinfo/main.cpp
deleted file mode 100644
index 3cf9709d09..0000000000
--- a/tests/benchmarks/corelib/io/qfileinfo/main.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-#include <QDebug>
-#include <qtest.h>
-#include <QTest>
-#include <QtCore/QCoreApplication>
-#include <QtCore/QFileInfo>
-#include <QtCore/QFile>
-
-#include "private/qfsfileengine_p.h"
-#include "../../../../shared/filesystem.h"
-
-class qfileinfo : public QObject
-{
- Q_OBJECT
-private slots:
- void existsTemporary();
- void existsStatic();
-#if defined(Q_OS_WIN)
- void symLinkTargetPerformanceLNK();
- void symLinkTargetPerformanceMounpoint();
-#endif
- void initTestCase();
- void cleanupTestCase();
-public:
- qfileinfo() : QObject() {};
-};
-
-void qfileinfo::initTestCase()
-{
-}
-
-void qfileinfo::cleanupTestCase()
-{
-}
-
-void qfileinfo::existsTemporary()
-{
- QString appPath = QCoreApplication::applicationFilePath();
- QBENCHMARK { QFileInfo(appPath).exists(); }
-}
-
-void qfileinfo::existsStatic()
-{
- QString appPath = QCoreApplication::applicationFilePath();
- QBENCHMARK { QFileInfo::exists(appPath); }
-}
-
-#if defined(Q_OS_WIN)
-void qfileinfo::symLinkTargetPerformanceLNK()
-{
- QVERIFY(QFile::link("file","link.lnk"));
- QFileInfo info("link.lnk");
- info.setCaching(false);
- QVERIFY(info.isSymLink());
- QString linkTarget;
- QBENCHMARK {
- for(int i=0; i<100; i++)
- linkTarget = info.symLinkTarget();
- }
- QVERIFY(QFile::remove("link.lnk"));
-}
-
-void qfileinfo::symLinkTargetPerformanceMounpoint()
-{
- wchar_t buffer[MAX_PATH];
- QString rootPath = QDir::toNativeSeparators(QDir::rootPath());
- QVERIFY(GetVolumeNameForVolumeMountPointW((LPCWSTR)rootPath.utf16(), buffer, MAX_PATH));
- QString rootVolume = QString::fromWCharArray(buffer);
- QString mountpoint = "mountpoint";
- rootVolume.replace("\\\\?\\","\\??\\");
- QString errorMessage;
- QVERIFY2(FileSystem::createNtfsJunction(rootVolume, mountpoint, &errorMessage) == ERROR_SUCCESS,
- qPrintable(errorMessage));
-
- QFileInfo info(mountpoint);
- info.setCaching(false);
- QVERIFY(info.isSymLink());
- QString linkTarget;
- QBENCHMARK {
- for(int i=0; i<100; i++)
- linkTarget = info.symLinkTarget();
- }
- QVERIFY(QDir().rmdir(mountpoint));
-}
-#endif
-
-QTEST_MAIN(qfileinfo)
-
-#include "main.moc"
diff --git a/tests/benchmarks/corelib/io/qfileinfo/tst_bench_qfileinfo.cpp b/tests/benchmarks/corelib/io/qfileinfo/tst_bench_qfileinfo.cpp
new file mode 100644
index 0000000000..2c626dde70
--- /dev/null
+++ b/tests/benchmarks/corelib/io/qfileinfo/tst_bench_qfileinfo.cpp
@@ -0,0 +1,77 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+#include <QDebug>
+#include <qtest.h>
+#include <QTest>
+#include <QtCore/QCoreApplication>
+#include <QtCore/QFileInfo>
+#include <QtCore/QFile>
+
+#include "private/qfsfileengine_p.h"
+#include "../../../../shared/filesystem.h"
+
+class tst_QFileInfo : public QObject
+{
+ Q_OBJECT
+private slots:
+ void existsTemporary();
+ void existsStatic();
+#if defined(Q_OS_WIN)
+ void symLinkTargetPerformanceLNK();
+ void junctionTargetPerformanceMountpoint();
+#endif
+};
+
+void tst_QFileInfo::existsTemporary()
+{
+ QString appPath = QCoreApplication::applicationFilePath();
+ QBENCHMARK { QFileInfo(appPath).exists(); }
+}
+
+void tst_QFileInfo::existsStatic()
+{
+ QString appPath = QCoreApplication::applicationFilePath();
+ QBENCHMARK { QFileInfo::exists(appPath); }
+}
+
+#if defined(Q_OS_WIN)
+void tst_QFileInfo::symLinkTargetPerformanceLNK()
+{
+ QVERIFY(QFile::link("file","link.lnk"));
+ QFileInfo info("link.lnk");
+ info.setCaching(false);
+ QVERIFY(info.isSymLink());
+ QString linkTarget;
+ QBENCHMARK {
+ for(int i=0; i<100; i++)
+ linkTarget = info.symLinkTarget();
+ }
+ QVERIFY(QFile::remove("link.lnk"));
+}
+
+void tst_QFileInfo::junctionTargetPerformanceMountpoint()
+{
+ wchar_t buffer[MAX_PATH];
+ QString rootPath = QDir::toNativeSeparators(QDir::rootPath());
+ QVERIFY(GetVolumeNameForVolumeMountPointW((LPCWSTR)rootPath.utf16(), buffer, MAX_PATH));
+ QString rootVolume = QString::fromWCharArray(buffer);
+ QString mountpoint = "mountpoint";
+ rootVolume.replace("\\\\?\\","\\??\\");
+ const auto result = FileSystem::createNtfsJunction(rootVolume, mountpoint);
+ QVERIFY2(result.dwErr == ERROR_SUCCESS, qPrintable(result.errorMessage));
+
+ QFileInfo info(mountpoint);
+ info.setCaching(false);
+ QVERIFY(info.isJunction());
+ QString junctionTarget;
+ QBENCHMARK {
+ for(int i=0; i<100; i++)
+ junctionTarget = info.junctionTarget();
+ }
+ QVERIFY(QDir().rmdir(mountpoint));
+}
+#endif
+
+QTEST_MAIN(tst_QFileInfo)
+
+#include "tst_bench_qfileinfo.moc"
diff --git a/tests/benchmarks/corelib/io/qiodevice/CMakeLists.txt b/tests/benchmarks/corelib/io/qiodevice/CMakeLists.txt
index 3af6d4f214..133a9a1ac3 100644
--- a/tests/benchmarks/corelib/io/qiodevice/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qiodevice/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qiodevice.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qiodevice Binary:
@@ -6,10 +7,7 @@
qt_internal_add_benchmark(tst_bench_qiodevice
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qiodevice.cpp
+ LIBRARIES
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qiodevice.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/corelib/io/qiodevice/main.cpp b/tests/benchmarks/corelib/io/qiodevice/tst_bench_qiodevice.cpp
index de4660a253..cae90631ee 100644
--- a/tests/benchmarks/corelib/io/qiodevice/main.cpp
+++ b/tests/benchmarks/corelib/io/qiodevice/tst_bench_qiodevice.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
#include <QDebug>
#include <QIODevice>
#include <QFile>
@@ -32,8 +7,7 @@
#include <qtest.h>
-
-class tst_qiodevice : public QObject
+class tst_QIODevice : public QObject
{
Q_OBJECT
private slots:
@@ -48,7 +22,7 @@ private:
};
-void tst_qiodevice::read_data()
+void tst_QIODevice::read_data()
{
QTest::addColumn<qint64>("size");
QTest::newRow("10k") << qint64(10 * 1024);
@@ -59,7 +33,7 @@ void tst_qiodevice::read_data()
QTest::newRow("1000000k") << qint64(1000000 * 1024);
}
-void tst_qiodevice::read_old()
+void tst_QIODevice::read_old()
{
QFETCH(qint64, size);
@@ -88,7 +62,7 @@ void tst_qiodevice::read_old()
}
}
-void tst_qiodevice::peekAndRead()
+void tst_QIODevice::peekAndRead()
{
QFETCH(qint64, size);
@@ -119,6 +93,6 @@ void tst_qiodevice::peekAndRead()
}
}
-QTEST_MAIN(tst_qiodevice)
+QTEST_MAIN(tst_QIODevice)
-#include "main.moc"
+#include "tst_bench_qiodevice.moc"
diff --git a/tests/benchmarks/corelib/io/qprocess/CMakeLists.txt b/tests/benchmarks/corelib/io/qprocess/CMakeLists.txt
index d599539142..3f3ffd3d70 100644
--- a/tests/benchmarks/corelib/io/qprocess/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qprocess/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qprocess.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
add_subdirectory(testProcessLoopback)
add_subdirectory(test)
diff --git a/tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt b/tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt
index ca7011a661..c8837d3d65 100644
--- a/tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qprocess/test/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from test.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qprocess Binary:
@@ -7,7 +8,7 @@
qt_internal_add_benchmark(tst_bench_qprocess
SOURCES
../tst_bench_qprocess.cpp
- PUBLIC_LIBRARIES
+ LIBRARIES
Qt::CorePrivate
Qt::Test
)
diff --git a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/CMakeLists.txt b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/CMakeLists.txt
index 896435b27b..cd486bd9cc 100644
--- a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/CMakeLists.txt
@@ -1,5 +1,8 @@
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
+
#####################################################################
## testProcessLoopback Binary:
#####################################################################
-add_executable(testProcessLoopback main.cpp)
+add_executable(testProcessLoopback loopback.cpp)
diff --git a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/loopback.cpp b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/loopback.cpp
new file mode 100644
index 0000000000..1f47f6b0f1
--- /dev/null
+++ b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/loopback.cpp
@@ -0,0 +1,19 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+
+
+#include <stdio.h>
+
+int main()
+{
+ char buffer[1024];
+ for (;;) {
+ size_t num = fread(buffer, 1, sizeof(buffer), stdin);
+ if (num <= 0)
+ break;
+ fwrite(buffer, num, 1, stdout);
+ fflush(stdout);
+ }
+
+ return 0;
+}
diff --git a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/main.cpp b/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/main.cpp
deleted file mode 100644
index 1773ba7496..0000000000
--- a/tests/benchmarks/corelib/io/qprocess/testProcessLoopback/main.cpp
+++ /dev/null
@@ -1,44 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-
-
-#include <stdio.h>
-
-int main()
-{
- char buffer[1024];
- for (;;) {
- size_t num = fread(buffer, 1, sizeof(buffer), stdin);
- if (num <= 0)
- break;
- fwrite(buffer, num, 1, stdout);
- fflush(stdout);
- }
-
- return 0;
-}
diff --git a/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp b/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp
index 7077ec631a..9cf87a6653 100644
--- a/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp
+++ b/tests/benchmarks/corelib/io/qprocess/tst_bench_qprocess.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2020 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 <QTest>
#include <QSignalSpy>
@@ -40,10 +15,16 @@ private slots:
void echoTest_performance();
};
+#ifdef Q_OS_WIN
+# define EXE ".exe"
+#else
+# define EXE ""
+#endif
+
void tst_QProcess::echoTest_performance()
{
QProcess process;
- process.start("testProcessLoopback/testProcessLoopback");
+ process.start(QFINDTESTDATA("../testProcessLoopback/testProcessLoopback" EXE));
QByteArray array;
array.resize(1024 * 1024);
@@ -62,9 +43,9 @@ void tst_QProcess::echoTest_performance()
while (stopWatch.elapsed() < 2000) {
process.write(array);
while (process.bytesToWrite() > 0) {
- int readCount = readyReadSpy.count();
+ int readCount = readyReadSpy.size();
QVERIFY(process.waitForBytesWritten(5000));
- if (readyReadSpy.count() == readCount)
+ if (readyReadSpy.size() == readCount)
QVERIFY(process.waitForReadyRead(5000));
}
diff --git a/tests/benchmarks/corelib/io/qtemporaryfile/CMakeLists.txt b/tests/benchmarks/corelib/io/qtemporaryfile/CMakeLists.txt
index a12bfd1260..a2a33a0dce 100644
--- a/tests/benchmarks/corelib/io/qtemporaryfile/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qtemporaryfile/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qtemporaryfile.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qtemporaryfile Binary:
@@ -6,10 +7,7 @@
qt_internal_add_benchmark(tst_bench_qtemporaryfile
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qtemporaryfile.cpp
+ LIBRARIES
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qtemporaryfile.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/corelib/io/qtemporaryfile/main.cpp b/tests/benchmarks/corelib/io/qtemporaryfile/main.cpp
deleted file mode 100644
index c50032d174..0000000000
--- a/tests/benchmarks/corelib/io/qtemporaryfile/main.cpp
+++ /dev/null
@@ -1,90 +0,0 @@
-/****************************************************************************
-**
-** 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$
-**
-****************************************************************************/
-#include <QDebug>
-#include <QIODevice>
-#include <QFile>
-#include <QString>
-#include <QTemporaryFile>
-#include <qtest.h>
-
-
-class tst_qtemporaryfile : public QObject
-{
- Q_OBJECT
-private slots:
- void openclose_data();
- void openclose();
- void readwrite_data() { openclose_data(); }
- void readwrite();
-
-private:
-};
-
-void tst_qtemporaryfile::openclose_data()
-{
- QTest::addColumn<qint64>("amount");
- QTest::newRow("100") << qint64(100);
- QTest::newRow("1000") << qint64(1000);
- QTest::newRow("10000") << qint64(10000);
-}
-
-void tst_qtemporaryfile::openclose()
-{
- QFETCH(qint64, amount);
-
- QBENCHMARK {
- for (qint64 i = 0; i < amount; ++i) {
- QTemporaryFile file;
- file.open();
- file.close();
- }
- }
-}
-
-void tst_qtemporaryfile::readwrite()
-{
- QFETCH(qint64, amount);
-
- const int dataSize = 4096;
- QByteArray data;
- data.fill('a', dataSize);
- QBENCHMARK {
- for (qint64 i = 0; i < amount; ++i) {
- QTemporaryFile file;
- file.open();
- file.write(data);
- file.seek(0);
- file.read(dataSize);
- file.close();
- }
- }
-}
-
-QTEST_MAIN(tst_qtemporaryfile)
-
-#include "main.moc"
diff --git a/tests/benchmarks/corelib/io/qtemporaryfile/tst_bench_qtemporaryfile.cpp b/tests/benchmarks/corelib/io/qtemporaryfile/tst_bench_qtemporaryfile.cpp
new file mode 100644
index 0000000000..c72b525827
--- /dev/null
+++ b/tests/benchmarks/corelib/io/qtemporaryfile/tst_bench_qtemporaryfile.cpp
@@ -0,0 +1,64 @@
+// Copyright (C) 2016 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
+#include <QDebug>
+#include <QIODevice>
+#include <QFile>
+#include <QString>
+#include <QTemporaryFile>
+#include <qtest.h>
+
+class tst_QTemporaryFile : public QObject
+{
+ Q_OBJECT
+private slots:
+ void openclose_data();
+ void openclose();
+ void readwrite_data() { openclose_data(); }
+ void readwrite();
+
+private:
+};
+
+void tst_QTemporaryFile::openclose_data()
+{
+ QTest::addColumn<qint64>("amount");
+ QTest::newRow("100") << qint64(100);
+ QTest::newRow("1000") << qint64(1000);
+ QTest::newRow("10000") << qint64(10000);
+}
+
+void tst_QTemporaryFile::openclose()
+{
+ QFETCH(qint64, amount);
+
+ QBENCHMARK {
+ for (qint64 i = 0; i < amount; ++i) {
+ QTemporaryFile file;
+ file.open();
+ file.close();
+ }
+ }
+}
+
+void tst_QTemporaryFile::readwrite()
+{
+ QFETCH(qint64, amount);
+
+ const int dataSize = 4096;
+ QByteArray data;
+ data.fill('a', dataSize);
+ QBENCHMARK {
+ for (qint64 i = 0; i < amount; ++i) {
+ QTemporaryFile file;
+ file.open();
+ file.write(data);
+ file.seek(0);
+ file.read(dataSize);
+ file.close();
+ }
+ }
+}
+
+QTEST_MAIN(tst_QTemporaryFile)
+
+#include "tst_bench_qtemporaryfile.moc"
diff --git a/tests/benchmarks/corelib/io/qtextstream/CMakeLists.txt b/tests/benchmarks/corelib/io/qtextstream/CMakeLists.txt
index 0393b91119..5e39b2fd90 100644
--- a/tests/benchmarks/corelib/io/qtextstream/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qtextstream/CMakeLists.txt
@@ -1,4 +1,5 @@
-# Generated from qtextstream.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_bench_qtextstream Binary:
@@ -6,10 +7,7 @@
qt_internal_add_benchmark(tst_bench_qtextstream
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qtextstream.cpp
+ LIBRARIES
Qt::Test
)
-
-#### Keys ignored in scope 1:.:.:qtextstream.pro:<TRUE>:
-# TEMPLATE = "app"
diff --git a/tests/benchmarks/corelib/io/qtextstream/main.cpp b/tests/benchmarks/corelib/io/qtextstream/tst_bench_qtextstream.cpp
index 03dc3d1694..74552b85cf 100644
--- a/tests/benchmarks/corelib/io/qtextstream/main.cpp
+++ b/tests/benchmarks/corelib/io/qtextstream/tst_bench_qtextstream.cpp
@@ -1,30 +1,5 @@
-/****************************************************************************
-**
-** Copyright (C) 2014 David Faure <david.faure@kdab.com>
-** 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) 2014 David Faure <david.faure@kdab.com>
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
#include <QDebug>
#include <QIODevice>
@@ -32,7 +7,7 @@
#include <QBuffer>
#include <qtest.h>
-class tst_qtextstream : public QObject
+class tst_QTextStream : public QObject
{
Q_OBJECT
private slots:
@@ -48,7 +23,7 @@ Q_DECLARE_METATYPE(Output);
enum Input { CharStarInput, QStringInput, CharInput, QCharInput };
Q_DECLARE_METATYPE(Input);
-void tst_qtextstream::writeSingleChar_data()
+void tst_QTextStream::writeSingleChar_data()
{
QTest::addColumn<Output>("output");
QTest::addColumn<Input>("input");
@@ -63,7 +38,7 @@ void tst_qtextstream::writeSingleChar_data()
QTest::newRow("device_qchar") << DeviceOutput << QCharInput;
}
-void tst_qtextstream::writeSingleChar()
+void tst_QTextStream::writeSingleChar()
{
QFETCH(Output, output);
QFETCH(Input, input);
@@ -115,6 +90,6 @@ void tst_qtextstream::writeSingleChar()
QCOMPARE(result.left(10), QString("hhhhhhhhhh"));
}
-QTEST_MAIN(tst_qtextstream)
+QTEST_MAIN(tst_QTextStream)
-#include "main.moc"
+#include "tst_bench_qtextstream.moc"
diff --git a/tests/benchmarks/corelib/io/qurl/CMakeLists.txt b/tests/benchmarks/corelib/io/qurl/CMakeLists.txt
index d38c8b18c0..fc8d48450d 100644
--- a/tests/benchmarks/corelib/io/qurl/CMakeLists.txt
+++ b/tests/benchmarks/corelib/io/qurl/CMakeLists.txt
@@ -1,23 +1,21 @@
-# Generated from qurl.pro.
+# Copyright (C) 2022 The Qt Company Ltd.
+# SPDX-License-Identifier: BSD-3-Clause
#####################################################################
## tst_qurl Binary:
#####################################################################
-qt_internal_add_benchmark(tst_qurl
+qt_internal_add_benchmark(tst_bench_qurl
SOURCES
- main.cpp
- PUBLIC_LIBRARIES
+ tst_bench_qurl.cpp
+ LIBRARIES
Qt::Test
)
-#### Keys ignored in scope 1:.:.:qurl.pro:<TRUE>:
-# TEMPLATE = "app"
-
## Scopes:
#####################################################################
-qt_internal_extend_target(tst_qurl CONDITION WIN32
+qt_internal_extend_target(tst_bench_qurl CONDITION WIN32
DEFINES
_CRT_SECURE_NO_WARNINGS
)
diff --git a/tests/benchmarks/corelib/io/qurl/main.cpp b/tests/benchmarks/corelib/io/qurl/tst_bench_qurl.cpp
index 5ad3c3bd47..87c4f51816 100644
--- a/tests/benchmarks/corelib/io/qurl/main.cpp
+++ b/tests/benchmarks/corelib/io/qurl/tst_bench_qurl.cpp
@@ -1,35 +1,10 @@
-/****************************************************************************
-**
-** 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
#include <qurl.h>
#include <qtest.h>
-class tst_qurl: public QObject
+class tst_QUrl : public QObject
{
Q_OBJECT
@@ -53,28 +28,28 @@ private:
void generateFirstRunData();
};
-void tst_qurl::emptyUrl()
+void tst_QUrl::emptyUrl()
{
QBENCHMARK {
QUrl url;
}
}
-void tst_qurl::relativeUrl()
+void tst_QUrl::relativeUrl()
{
QBENCHMARK {
QUrl url("pics/avatar.png");
}
}
-void tst_qurl::absoluteUrl()
+void tst_QUrl::absoluteUrl()
{
QBENCHMARK {
QUrl url("/tmp/avatar.png");
}
}
-void tst_qurl::generateFirstRunData()
+void tst_QUrl::generateFirstRunData()
{
QTest::addColumn<bool>("firstRun");
@@ -82,12 +57,12 @@ void tst_qurl::generateFirstRunData()
QTest::newRow("subsequent runs") << false;
}
-void tst_qurl::isRelative_data()
+void tst_QUrl::isRelative_data()
{
generateFirstRunData();
}
-void tst_qurl::isRelative()
+void tst_QUrl::isRelative()
{
QFETCH(bool, firstRun);
if (firstRun) {
@@ -103,12 +78,12 @@ void tst_qurl::isRelative()
}
}
-void tst_qurl::toLocalFile_data()
+void tst_QUrl::toLocalFile_data()
{
generateFirstRunData();
}
-void tst_qurl::toLocalFile()
+void tst_QUrl::toLocalFile()
{
QFETCH(bool, firstRun);
if (firstRun) {
@@ -124,12 +99,12 @@ void tst_qurl::toLocalFile()
}
}
-void tst_qurl::toString_data()
+void tst_QUrl::toString_data()
{
generateFirstRunData();
}
-void tst_qurl::toString()
+void tst_QUrl::toString()
{
QFETCH(bool, firstRun);
if(firstRun) {
@@ -145,35 +120,37 @@ void tst_qurl::toString()
}
}
-void tst_qurl::resolved_data()
+void tst_QUrl::resolved_data()
{
generateFirstRunData();
}
-void tst_qurl::resolved()
+void tst_QUrl::resolved()
{
QFETCH(bool, firstRun);
- if(firstRun) {
+ QUrl expect("/home/user/pics/avatar.png"), actual;
+ if (firstRun) {
QBENCHMARK {
QUrl baseUrl("/home/user/");
QUrl url("pics/avatar.png");
- baseUrl.resolved(url);
+ actual = baseUrl.resolved(url);
}
} else {
QUrl baseUrl("/home/user/");
QUrl url("pics/avatar.png");
QBENCHMARK {
- baseUrl.resolved(url);
+ actual = baseUrl.resolved(url);
}
}
+ QCOMPARE(actual, expect);
}
-void tst_qurl::equality_data()
+void tst_QUrl::equality_data()
{
generateFirstRunData();
}
-void tst_qurl::equality()
+void tst_QUrl::equality()
{
QFETCH(bool, firstRun);
if(firstRun) {
@@ -186,12 +163,12 @@ void tst_qurl::equality()
QUrl url("pics/avatar.png");
QUrl url2("pics/avatar2.png");
QBENCHMARK {
- url == url2;
+ [[maybe_unused]] auto r = url == url2;
}
}
}
-void tst_qurl::qmlPropertyWriteUseCase()
+void tst_QUrl::qmlPropertyWriteUseCase()
{
QUrl base("file:///home/user/qt/examples/declarative/samegame/SamegameCore/");
QString str("pics/redStar.png");
@@ -203,6 +180,6 @@ void tst_qurl::qmlPropertyWriteUseCase()
}
}
-QTEST_MAIN(tst_qurl)
+QTEST_MAIN(tst_QUrl)
-#include "main.moc"
+#include "tst_bench_qurl.moc"