1 /**************************************************************************** |
1 /**************************************************************************** |
2 ** |
2 ** |
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). |
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
4 ** All rights reserved. |
4 ** All rights reserved. |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
6 ** |
6 ** |
7 ** This file is part of the test suite of the Qt Toolkit. |
7 ** This file is part of the test suite of the Qt Toolkit. |
8 ** |
8 ** |
53 Q_OBJECT |
53 Q_OBJECT |
54 // do not use on symbian.. 100 MB is too large.. |
54 // do not use on symbian.. 100 MB is too large.. |
55 // but.. this is a manual test anyway, so :) |
55 // but.. this is a manual test anyway, so :) |
56 protected: |
56 protected: |
57 void qnamFileRead_iteration(QNetworkAccessManager &manager, QNetworkRequest &request); |
57 void qnamFileRead_iteration(QNetworkAccessManager &manager, QNetworkRequest &request); |
|
58 void qnamImmediateFileRead_iteration(QNetworkAccessManager &manager, QNetworkRequest &request); |
58 void qfileFileRead_iteration(); |
59 void qfileFileRead_iteration(); |
59 static const int iterations = 10; |
60 static const int iterations = 10; |
60 |
61 |
61 private slots: |
62 private slots: |
62 void qnamFileRead(); |
63 void qnamFileRead(); |
|
64 void qnamImmediateFileRead(); |
63 void qfileFileRead(); |
65 void qfileFileRead(); |
64 |
66 |
65 void initTestCase(); |
67 void initTestCase(); |
66 void cleanupTestCase(); |
68 void cleanupTestCase(); |
67 |
69 |
122 qDebug() << endl << "Finished!"; |
124 qDebug() << endl << "Finished!"; |
123 qDebug() << "Bytes:" << size; |
125 qDebug() << "Bytes:" << size; |
124 qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec"; |
126 qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec"; |
125 } |
127 } |
126 |
128 |
|
129 void qfile_vs_qnetworkaccessmanager::qnamImmediateFileRead_iteration(QNetworkAccessManager &manager, QNetworkRequest &request) |
|
130 { |
|
131 QNetworkReply* reply = manager.get(request); |
|
132 QVERIFY(reply->isFinished()); // should be like that! |
|
133 QByteArray qba = reply->readAll(); |
|
134 delete reply; |
|
135 } |
|
136 |
|
137 void qfile_vs_qnetworkaccessmanager::qnamImmediateFileRead() |
|
138 { |
|
139 QNetworkAccessManager manager; |
|
140 QTime t; |
|
141 QNetworkRequest request(QUrl(testFile.fileName())); |
|
142 |
|
143 // do 3 dry runs for cache warmup |
|
144 qnamImmediateFileRead_iteration(manager, request); |
|
145 qnamImmediateFileRead_iteration(manager, request); |
|
146 qnamImmediateFileRead_iteration(manager, request); |
|
147 |
|
148 t.start(); |
|
149 // 10 real runs |
|
150 QBENCHMARK_ONCE { |
|
151 for (int i = 0; i < iterations; i++) { |
|
152 qnamImmediateFileRead_iteration(manager, request); |
|
153 } |
|
154 } |
|
155 |
|
156 qint64 elapsed = t.elapsed(); |
|
157 qDebug() << endl << "Finished!"; |
|
158 qDebug() << "Bytes:" << size; |
|
159 qDebug() << "Speed:" << (qreal(size*iterations) / 1024.0) / (qreal(elapsed) / 1000.0) << "KB/sec"; |
|
160 } |
|
161 |
127 void qfile_vs_qnetworkaccessmanager::qfileFileRead_iteration() |
162 void qfile_vs_qnetworkaccessmanager::qfileFileRead_iteration() |
128 { |
163 { |
129 testFile.reset(); |
164 testFile.reset(); |
130 QByteArray qba = testFile.readAll(); |
165 QByteArray qba = testFile.readAll(); |
131 } |
166 } |