diff options
Diffstat (limited to 'tests/benchmarks')
7 files changed, 91 insertions, 110 deletions
diff --git a/tests/benchmarks/corelib/io/qdiriterator/main.cpp b/tests/benchmarks/corelib/io/qdiriterator/main.cpp index eae752d99a..60c75ead4d 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/main.cpp +++ b/tests/benchmarks/corelib/io/qdiriterator/main.cpp @@ -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" diff --git a/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro b/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro index 061b22a5d1..4b28946f18 100644 --- a/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro +++ b/tests/benchmarks/corelib/io/qdiriterator/qdiriterator.pro @@ -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 diff --git a/tests/benchmarks/corelib/kernel/qobject/main.cpp b/tests/benchmarks/corelib/kernel/qobject/main.cpp index 04ca69ad3b..918227f74e 100644 --- a/tests/benchmarks/corelib/kernel/qobject/main.cpp +++ b/tests/benchmarks/corelib/kernel/qobject/main.cpp @@ -51,8 +51,55 @@ private slots: void connect_disconnect_benchmark_data(); void connect_disconnect_benchmark(); void receiver_destroyed_benchmark(); + + void stdAllocator(); }; +class QObjectUsingStandardAllocator : public QObject +{ + Q_OBJECT +public: + QObjectUsingStandardAllocator() + { + } +}; + +template<class T> +inline void allocator() +{ + // We need to allocate certain amount of objects otherwise the new implementation + // may re-use the previous allocation, hiding the somehow high cost of allocation. It + // also helps us to reduce the noise ratio, which is high for memory allocation. + // + // The check depends on memory allocation performance, which is quite non-deterministic. + // When a new memory is requested, the new operator, depending on implementation, is trying + // to re-use existing, already allocated for the process memory. If there is not enough, it + // asks OS to give more. Of course the first case is faster then the second. In the same + // time, from an application perspective the first is also more likely. + // + // As a result, depending on which use-case one wants to test, it may be recommended to run this + // test in separation from others, to "force" expensive code path in the memory allocation. + // + // The time based results are heavily affected by background noise. One really needs to + // prepare OS (no other tasks, CPU and RAM reservations) to run this test, or use + // instruction counting which seems to be less fragile. + + const int count = 256 * 1024; + + QScopedPointer<T> objects[count]; + QBENCHMARK_ONCE { + for (int i = 0; i < count; ++i) + objects[i].reset(new T); + for (int i = 0; i < count; ++i) + objects[i].reset(); + } +} + +void QObjectBenchmark::stdAllocator() +{ + allocator<QObjectUsingStandardAllocator>(); +} + struct Functor { void operator()(){} }; diff --git a/tests/benchmarks/corelib/tools/qvector/outofline.cpp b/tests/benchmarks/corelib/tools/qvector/outofline.cpp index 76a4edaa10..7182a43008 100644 --- a/tests/benchmarks/corelib/tools/qvector/outofline.cpp +++ b/tests/benchmarks/corelib/tools/qvector/outofline.cpp @@ -54,7 +54,7 @@ QVector<double> mixedvector_fill_and_return_helper() std::vector<double> v(N); for (int i = 0; i != N; ++i) v[i] = i; - return QVector<double>::fromStdVector(v); + return QVector<double>(v.begin(), v.end()); } diff --git a/tests/benchmarks/corelib/tools/qvector/qrawvector.h b/tests/benchmarks/corelib/tools/qvector/qrawvector.h index 16a911c63a..9ad5f771bd 100644 --- a/tests/benchmarks/corelib/tools/qvector/qrawvector.h +++ b/tests/benchmarks/corelib/tools/qvector/qrawvector.h @@ -130,78 +130,9 @@ public: bool contains(const T &t) const; int count(const T &t) const; -#ifdef QT_STRICT_ITERATORS - class iterator { - public: - T *i; - typedef std::random_access_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; - typedef T value_type; - typedef T *pointer; - typedef T &reference; - - inline iterator() : i(0) {} - inline iterator(T *n) : i(n) {} - inline iterator(const iterator &o): i(o.i){} - inline T &operator*() const { return *i; } - inline T *operator->() const { return i; } - inline T &operator[](int j) const { return *(i + j); } - inline bool operator==(const iterator &o) const { return i == o.i; } - inline bool operator!=(const iterator &o) const { return i != o.i; } - inline bool operator<(const iterator& other) const { return i < other.i; } - inline bool operator<=(const iterator& other) const { return i <= other.i; } - inline bool operator>(const iterator& other) const { return i > other.i; } - inline bool operator>=(const iterator& other) const { return i >= other.i; } - inline iterator &operator++() { ++i; return *this; } - inline iterator operator++(int) { T *n = i; ++i; return n; } - inline iterator &operator--() { i--; return *this; } - inline iterator operator--(int) { T *n = i; i--; return n; } - inline iterator &operator+=(int j) { i+=j; return *this; } - inline iterator &operator-=(int j) { i-=j; return *this; } - inline iterator operator+(int j) const { return iterator(i+j); } - inline iterator operator-(int j) const { return iterator(i-j); } - inline int operator-(iterator j) const { return i - j.i; } - }; - friend class iterator; - - class const_iterator { - public: - T *i; - typedef std::random_access_iterator_tag iterator_category; - typedef ptrdiff_t difference_type; - typedef T value_type; - typedef const T *pointer; - typedef const T &reference; - - inline const_iterator() : i(0) {} - inline const_iterator(T *n) : i(n) {} - inline const_iterator(const const_iterator &o): i(o.i) {} - inline explicit const_iterator(const iterator &o): i(o.i) {} - inline const T &operator*() const { return *i; } - inline const T *operator->() const { return i; } - inline const T &operator[](int j) const { return *(i + j); } - inline bool operator==(const const_iterator &o) const { return i == o.i; } - inline bool operator!=(const const_iterator &o) const { return i != o.i; } - inline bool operator<(const const_iterator& other) const { return i < other.i; } - inline bool operator<=(const const_iterator& other) const { return i <= other.i; } - inline bool operator>(const const_iterator& other) const { return i > other.i; } - inline bool operator>=(const const_iterator& other) const { return i >= other.i; } - inline const_iterator &operator++() { ++i; return *this; } - inline const_iterator operator++(int) { T *n = i; ++i; return n; } - inline const_iterator &operator--() { i--; return *this; } - inline const_iterator operator--(int) { T *n = i; i--; return n; } - inline const_iterator &operator+=(int j) { i+=j; return *this; } - inline const_iterator &operator-=(int j) { i+=j; return *this; } - inline const_iterator operator+(int j) const { return const_iterator(i+j); } - inline const_iterator operator-(int j) const { return const_iterator(i-j); } - inline int operator-(const_iterator j) const { return i - j.i; } - }; - friend class const_iterator; -#else // STL-style typedef T *iterator; typedef const T *const_iterator; -#endif inline iterator begin() { return m_begin; } inline const_iterator begin() const { return m_begin; } inline const_iterator constBegin() const { return m_begin; } @@ -280,11 +211,7 @@ private: } static Q_DECL_CONSTEXPR int alignOfTypedData() { -#ifdef Q_ALIGNOF - return Q_ALIGNOF(AlignmentDummy); -#else - return sizeof(void *); -#endif + return alignof(AlignmentDummy); } public: diff --git a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp index 46bb1791b4..1f3f38eaaf 100644 --- a/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp +++ b/tests/benchmarks/network/access/qfile_vs_qnetworkaccessmanager/main.cpp @@ -105,7 +105,7 @@ void qfile_vs_qnetworkaccessmanager::qnamFileRead() } qint64 elapsed = t.elapsed(); - qDebug() << endl << "Finished!"; + qDebug() << Qt::endl << "Finished!"; qDebug() << "Bytes:" << size; qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec"; } @@ -138,7 +138,7 @@ void qfile_vs_qnetworkaccessmanager::qnamImmediateFileRead() } qint64 elapsed = t.elapsed(); - qDebug() << endl << "Finished!"; + qDebug() << Qt::endl << "Finished!"; qDebug() << "Bytes:" << size; qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec"; } @@ -167,7 +167,7 @@ void qfile_vs_qnetworkaccessmanager::qfileFileRead() } qint64 elapsed = t.elapsed(); - qDebug() << endl << "Finished!"; + qDebug() << Qt::endl << "Finished!"; qDebug() << "Bytes:" << size; qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec"; } diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp index c182ef7ebf..6dd7eaee6b 100644 --- a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -544,15 +544,10 @@ void tst_qnetworkreply::echoPerformance() void tst_qnetworkreply::preConnectEncrypted() { QFETCH(int, sleepTime); - QFETCH(QSslConfiguration, sslConfiguration); - bool spdyEnabled = !sslConfiguration.isNull(); - QString hostName = QLatin1String("www.google.com"); QNetworkAccessManager manager; QNetworkRequest request(QUrl("https://" + hostName)); - if (spdyEnabled) - request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); // make sure we have a full request including // DNS lookup, TCP and SSL handshakes @@ -578,12 +573,7 @@ void tst_qnetworkreply::preConnectEncrypted() manager.clearAccessCache(); // now try to make the connection beforehand - if (spdyEnabled) { - request.setAttribute(QNetworkRequest::SpdyAllowedAttribute, true); - manager.connectToHostEncrypted(hostName, 443, sslConfiguration); - } else { - manager.connectToHostEncrypted(hostName); - } + manager.connectToHostEncrypted(hostName); QTestEventLoop::instance().enterLoopMSecs(sleepTime); // now make another request and hopefully use the existing connection @@ -591,8 +581,6 @@ void tst_qnetworkreply::preConnectEncrypted() QNetworkReply *preConnectReply = normalResult.first; QVERIFY(!QTestEventLoop::instance().timeout()); QVERIFY(preConnectReply->error() == QNetworkReply::NoError); - bool spdyWasUsed = preConnectReply->attribute(QNetworkRequest::SpdyWasUsedAttribute).toBool(); - QCOMPARE(spdyEnabled, spdyWasUsed); qint64 preConnectElapsed = preConnectResult.second; qDebug() << request.url().toString() << "full request:" << normalElapsed << "ms, pre-connect request:" << preConnectElapsed << "ms, difference:" @@ -605,27 +593,11 @@ void tst_qnetworkreply::preConnectEncrypted_data() { #ifndef QT_NO_OPENSSL QTest::addColumn<int>("sleepTime"); - QTest::addColumn<QSslConfiguration>("sslConfiguration"); - // start a new normal request after preconnecting is done - QTest::newRow("HTTPS-2secs") << 2000 << QSslConfiguration(); + QTest::newRow("HTTPS-2secs") << 2000; // start a new normal request while preconnecting is in-flight - QTest::newRow("HTTPS-100ms") << 100 << QSslConfiguration(); - - QSslConfiguration spdySslConf = QSslConfiguration::defaultConfiguration(); - QList<QByteArray> nextProtocols = QList<QByteArray>() - << QSslConfiguration::NextProtocolSpdy3_0 - << QSslConfiguration::NextProtocolHttp1_1; - spdySslConf.setAllowedNextProtocols(nextProtocols); - -#if defined(QT_BUILD_INTERNAL) && !defined(QT_NO_SSL) && OPENSSL_VERSION_NUMBER >= 0x1000100fL && !defined(OPENSSL_NO_TLSEXT) && !defined(OPENSSL_NO_NEXTPROTONEG) - // start a new SPDY request while preconnecting is done - QTest::newRow("SPDY-2secs") << 2000 << spdySslConf; - - // start a new SPDY request while preconnecting is in-flight - QTest::newRow("SPDY-100ms") << 100 << spdySslConf; -#endif // defined (QT_BUILD_INTERNAL) && !defined(QT_NO_SSL) ... + QTest::newRow("HTTPS-100ms") << 100; #endif // QT_NO_OPENSSL } |