summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/io
diff options
context:
space:
mode:
authorAlex Trotsenko <alex1973tr@gmail.com>2016-09-17 16:43:02 +0300
committerAlex Trotsenko <alex1973tr@gmail.com>2017-02-09 18:46:24 +0000
commit6e8fcab7e07717526c8ea6eac8785bf27fa090c3 (patch)
treea6ea9825b55b3b406515e88462c54b448ff672a6 /tests/benchmarks/corelib/io
parent60563855e589cb51b4966ca51a4d390a2f1609a4 (diff)
Improve QIODevice::peek() performance on buffered devices
Since 5.7, QIODevice::peek() implementation is based on transaction mechanism. While technically it's correct, seeking backward on a buffered random-access device clears the internal buffer that affects the performance of reading. To solve the problem, this patch implements peek mode directly inside the reading procedure. Task-number: QTBUG-56032 Change-Id: Ic5269f76e44c491a0309e13aba87fa7cf7b9259f Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/benchmarks/corelib/io')
-rw-r--r--tests/benchmarks/corelib/io/qiodevice/main.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/io/qiodevice/main.cpp b/tests/benchmarks/corelib/io/qiodevice/main.cpp
index b106a9fd3d..de4660a253 100644
--- a/tests/benchmarks/corelib/io/qiodevice/main.cpp
+++ b/tests/benchmarks/corelib/io/qiodevice/main.cpp
@@ -39,6 +39,8 @@ class tst_qiodevice : public QObject
private slots:
void read_old();
void read_old_data() { read_data(); }
+ void peekAndRead();
+ void peekAndRead_data() { read_data(); }
//void read_new();
//void read_new_data() { read_data(); }
private:
@@ -86,6 +88,36 @@ void tst_qiodevice::read_old()
}
}
+void tst_qiodevice::peekAndRead()
+{
+ QFETCH(qint64, size);
+
+ QString name = "tmp" + QString::number(size);
+
+ {
+ QFile file(name);
+ file.open(QIODevice::WriteOnly);
+ file.seek(size);
+ file.write("x", 1);
+ file.close();
+ }
+
+ QBENCHMARK {
+ QFile file(name);
+ file.open(QIODevice::ReadOnly);
+
+ QByteArray ba(size / 1024, Qt::Uninitialized);
+ while (!file.atEnd()) {
+ file.peek(ba.data(), ba.size());
+ file.read(ba.data(), ba.size());
+ }
+ }
+
+ {
+ QFile file(name);
+ file.remove();
+ }
+}
QTEST_MAIN(tst_qiodevice)