qdiriterator benchmark: test against std::filesystem
If c++17 is available and the header is available (not experimental/filesystem) then we'll try std::filesystem::recursive_directory_iterator as well. Results on my PC (Windows, VS 2019): PASS : tst_qdiriterator::posix(C:\depot\qt\main/src/corelib) RESULT : tst_qdiriterator::posix():"C:\depot\qt\main/src/corelib": 23 msecs per iteration (total: 94, iterations: 4) PASS : tst_qdiriterator::diriterator(C:\depot\qt\main/src/corelib) RESULT : tst_qdiriterator::diriterator():"C:\depot\qt\main/src/corelib": 17 msecs per iteration (total: 71, iterations: 4) PASS : tst_qdiriterator::stdRecursiveDirectoryIterator(C:\depot\qt\main/src/corelib) RESULT : tst_qdiriterator::stdRecursiveDirectoryIterator():"C:\depot\qt\main/src/corelib": 6.7 msecs per iteration (total: 54, iterations: 8) PASS : tst_qdiriterator::fsiterator(C:\depot\qt\main/src/corelib) RESULT : tst_qdiriterator::fsiterator():"C:\depot\qt\main/src/corelib": 23 msecs per iteration (total: 92, iterations: 4) And as a drive-by fix: move the 'data' function out of the private slots so it is not invoked as a test function (it doesn't cause any problems but is ultimately pointless). Change-Id: Ia160ee276423ec51e35e554a4cd63d4d940c0e6a Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
This commit is contained in:
parent
9294d02395
commit
399f815143
@ -44,9 +44,19 @@
|
||||
|
||||
#include "qfilesystemiterator.h"
|
||||
|
||||
#if QT_HAS_INCLUDE(<filesystem>) && defined(__cpp_lib_filesystem) && __cpp_lib_filesystem >= 201703L
|
||||
#define HAS_STD_FILESYSTEM
|
||||
#endif
|
||||
|
||||
#ifdef HAS_STD_FILESYSTEM
|
||||
#include <filesystem>
|
||||
#endif
|
||||
|
||||
class tst_qdiriterator : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
void data();
|
||||
private slots:
|
||||
void posix();
|
||||
void posix_data() { data(); }
|
||||
@ -54,7 +64,8 @@ private slots:
|
||||
void diriterator_data() { data(); }
|
||||
void fsiterator();
|
||||
void fsiterator_data() { data(); }
|
||||
void data();
|
||||
void stdRecursiveDirectoryIterator();
|
||||
void stdRecursiveDirectoryIterator_data() { data(); }
|
||||
};
|
||||
|
||||
|
||||
@ -235,6 +246,28 @@ void tst_qdiriterator::fsiterator()
|
||||
qDebug() << count;
|
||||
}
|
||||
|
||||
void tst_qdiriterator::stdRecursiveDirectoryIterator()
|
||||
{
|
||||
#ifdef HAS_STD_FILESYSTEM
|
||||
QFETCH(QByteArray, dirpath);
|
||||
|
||||
int count = 0;
|
||||
|
||||
QBENCHMARK {
|
||||
int c = 0;
|
||||
for (auto obj : std::filesystem::recursive_directory_iterator(dirpath.data())) {
|
||||
if (obj.is_directory())
|
||||
continue;
|
||||
c++;
|
||||
}
|
||||
count = c;
|
||||
}
|
||||
qDebug() << count;
|
||||
#else
|
||||
QSKIP("Not supported.");
|
||||
#endif
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_qdiriterator)
|
||||
|
||||
#include "main.moc"
|
||||
|
@ -3,6 +3,8 @@ TARGET = tst_bench_qdiriterator
|
||||
QT = core testlib
|
||||
|
||||
CONFIG += release
|
||||
# Enable c++17 support for std::filesystem
|
||||
qtConfig(c++1z): CONFIG += c++17
|
||||
|
||||
SOURCES += main.cpp qfilesystemiterator.cpp
|
||||
HEADERS += qfilesystemiterator.h
|
||||
|
Loading…
Reference in New Issue
Block a user