diff options
author | Markus Goetz <Markus.Goetz@nokia.com> | 2010-09-29 10:07:59 (GMT) |
---|---|---|
committer | Markus Goetz <Markus.Goetz@nokia.com> | 2010-09-29 11:01:00 (GMT) |
commit | 7093399e1849f6344a5c3c45ef26f2dda4060ebe (patch) | |
tree | ca8b3d0db6059032e4a0d092ebac18529db56c12 /tests | |
parent | cf4f2847c1a1df101e2983a0e1e8682ace323c0d (diff) | |
download | Qt-7093399e1849f6344a5c3c45ef26f2dda4060ebe.zip Qt-7093399e1849f6344a5c3c45ef26f2dda4060ebe.tar.gz Qt-7093399e1849f6344a5c3c45ef26f2dda4060ebe.tar.bz2 |
QNAM: Enhance the zerocopy download buffer benchmark
Measure the variant too where a download buffer was requested
but the read() functions are then used.
Reviewed-by: TrustMe
Diffstat (limited to 'tests')
-rw-r--r-- | tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp | 43 |
1 files changed, 30 insertions, 13 deletions
diff --git a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp index f75d681..6b94f3c 100644 --- a/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp +++ b/tests/benchmarks/network/access/qnetworkreply/tst_qnetworkreply.cpp @@ -654,46 +654,63 @@ void tst_qnetworkreply::httpDownloadPerformance() << ((UploadSize/1024.0)/(elapsed/1000.0)) << " kB/sec"; }; +enum HttpDownloadPerformanceDownloadBufferTestType { + JustDownloadBuffer, + DownloadBufferButUseRead, + NoDownloadBuffer +}; +Q_DECLARE_METATYPE(HttpDownloadPerformanceDownloadBufferTestType) + class HttpDownloadPerformanceClientDownloadBuffer : QObject { Q_OBJECT private: - bool useDownloadBuffer; + HttpDownloadPerformanceDownloadBufferTestType testType; QNetworkReply *reply; qint64 uploadSize; QList<qint64> bytesAvailableList; public: - HttpDownloadPerformanceClientDownloadBuffer (QNetworkReply *reply, bool useDownloadBuffer, qint64 uploadSize) - : useDownloadBuffer(useDownloadBuffer), reply(reply), uploadSize(uploadSize) + HttpDownloadPerformanceClientDownloadBuffer (QNetworkReply *reply, HttpDownloadPerformanceDownloadBufferTestType testType, qint64 uploadSize) + : testType(testType), reply(reply), uploadSize(uploadSize) { connect(reply, SIGNAL(finished()), this, SLOT(finishedSlot())); } public slots: void finishedSlot() { - if (useDownloadBuffer) { + if (testType == JustDownloadBuffer) { + // We have a download buffer and use it. This should be the fastest benchmark result. QVariant downloadBufferAttribute = reply->attribute(QNetworkRequest::DownloadBufferAttribute); QSharedPointer<char> data = downloadBufferAttribute.value<QSharedPointer<char> >(); - } else { + } else if (testType == DownloadBufferButUseRead) { + // We had a download buffer but we benchmark here the "legacy" read() way to access it + char* replyData = (char*) qMalloc(uploadSize); + QVERIFY(reply->read(replyData, uploadSize) == uploadSize); + qFree(replyData); + } else if (testType == NoDownloadBuffer) { // We did not have a download buffer but we still need to benchmark having the data, e.g. reading it all. + // This should be the slowest benchmark result. char* replyData = (char*) qMalloc(uploadSize); QVERIFY(reply->read(replyData, uploadSize) == uploadSize); qFree(replyData); } + + QMetaObject::invokeMethod(&QTestEventLoop::instance(), "exitLoop", Qt::QueuedConnection); } }; void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer_data() { - QTest::addColumn<bool>("useDownloadBuffer"); + QTest::addColumn<HttpDownloadPerformanceDownloadBufferTestType>("testType"); - QTest::newRow("use-download-buffer") << true; - QTest::newRow("do-not-use-download-buffer") << false; + QTest::newRow("use-download-buffer") << JustDownloadBuffer; + QTest::newRow("use-download-buffer-but-use-read") << DownloadBufferButUseRead; + QTest::newRow("do-not-use-download-buffer") << NoDownloadBuffer; } // Please note that the whole "zero copy" download buffer API is private right now. Do not use it. void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer() { - QFETCH(bool, useDownloadBuffer); + QFETCH(HttpDownloadPerformanceDownloadBufferTestType, testType); // On my Linux Desktop the results are already visible with 128 kB, however we use this to have good results. #if defined(Q_OS_SYMBIAN) || defined(Q_WS_WINCE_WM) @@ -706,18 +723,18 @@ void tst_qnetworkreply::httpDownloadPerformanceDownloadBuffer() HttpDownloadPerformanceServer server(UploadSize, true, false); QNetworkRequest request(QUrl("http://127.0.0.1:" + QString::number(server.serverPort()) + "/?bare=1")); - if (useDownloadBuffer) + if (testType == JustDownloadBuffer || testType == DownloadBufferButUseRead) request.setAttribute(QNetworkRequest::MaximumDownloadBufferSizeAttribute, 1024*1024*128); // 128 MB is max allowed QNetworkAccessManager manager; QNetworkReplyPtr reply = manager.get(request); - HttpDownloadPerformanceClientDownloadBuffer client(reply, useDownloadBuffer, UploadSize); + HttpDownloadPerformanceClientDownloadBuffer client(reply, testType, UploadSize); - connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); - QBENCHMARK { + QBENCHMARK_ONCE { QTestEventLoop::instance().enterLoop(40); QCOMPARE(reply->error(), QNetworkReply::NoError); + QVERIFY(reply->isFinished()); QVERIFY(!QTestEventLoop::instance().timeout()); } } |