summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorShane Kearns <ext-shane.2.kearns@nokia.com>2012-03-08 11:45:05 (GMT)
committerQt by Nokia <qt-info@nokia.com>2012-03-13 14:40:50 (GMT)
commita3a2ff59284840f1980197e3f6d06d99fcc0f512 (patch)
tree95226afc1dfb521840e1c7f093ab149aaac85ff4 /tests/benchmarks
parent5bce44ef030a18d7ed3f6e3abf824d42ab84bf70 (diff)
downloadQt-a3a2ff59284840f1980197e3f6d06d99fcc0f512.zip
Qt-a3a2ff59284840f1980197e3f6d06d99fcc0f512.tar.gz
Qt-a3a2ff59284840f1980197e3f6d06d99fcc0f512.tar.bz2
Optimise QFile::seek that doesn't move the file pointer
If the seek position matches the current file position, then avoid doing an implicit flush that could be expensive. Change-Id: I019858ffb36fe832b9aee8da0a7803cafc8f7f75 Reviewed-by: Jaakko Helanti <ext-jaakko.helanti@nokia.com> Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/corelib/io/qfile/main.cpp104
1 files changed, 104 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/io/qfile/main.cpp b/tests/benchmarks/corelib/io/qfile/main.cpp
index a37b11a..00d6d79 100644
--- a/tests/benchmarks/corelib/io/qfile/main.cpp
+++ b/tests/benchmarks/corelib/io/qfile/main.cpp
@@ -113,6 +113,13 @@ private slots:
void readBigFile_posix();
void readBigFile_Win32();
+ void writeFileSequential_data();
+ void writeFileSequential();
+ void writeFileBackwards_data();
+ void writeFileBackwards();
+ void writeFileSequentialWithSeeks_data();
+ void writeFileSequentialWithSeeks();
+
private:
void readBigFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b);
void readBigFile();
@@ -678,6 +685,103 @@ void tst_qfile::readSmallFiles()
delete[] buffer;
}
+void tst_qfile::writeFileSequential_data()
+{
+ QTest::addColumn<int>("blockSize");
+ QTest::addColumn<QString>("path");
+
+ QTest::newRow("internal 16b") << 16 << QDir::tempPath();
+ QTest::newRow("internal 512b") << 512 << QDir::tempPath();
+ QTest::newRow("internal 4k") << 4096 << QDir::tempPath();
+ QTest::newRow("internal 16k") << 16384 << QDir::tempPath();
+ QTest::newRow("internal 64k") << 65536 << QDir::tempPath();
+
+ //slow media (e.g. SD card)
+ QString externalPath;
+#ifdef Q_OS_SYMBIAN
+ externalPath = "E:/";
+#endif
+ if (!externalPath.isEmpty()) {
+ QTest::newRow("external 16b") << 16 << externalPath;
+ QTest::newRow("external 512b") << 512 << externalPath;
+ QTest::newRow("external 4k") << 4096 << externalPath;
+ QTest::newRow("external 16k") << 16384 << externalPath;
+ QTest::newRow("external 64k") << 65536 << externalPath;
+ }
+}
+
+void tst_qfile::writeFileSequential()
+{
+ const qint64 limit = 1024 * 1024;
+ QFETCH(int, blockSize);
+ QFETCH(QString, path);
+ QTemporaryFile f;
+ f.setFileTemplate(path);
+ QByteArray block;
+ block.fill('@', blockSize);
+ QBENCHMARK {
+ QVERIFY(f.open());
+ for (qint64 pos = 0; pos < limit; pos += blockSize) {
+ QVERIFY(f.write(block));
+ }
+ QVERIFY(f.flush());
+ QCOMPARE(f.size(), limit);
+ f.close();
+ }
+}
+
+void tst_qfile::writeFileBackwards_data()
+{
+ writeFileSequential_data();
+}
+
+void tst_qfile::writeFileBackwards()
+{
+ const qint64 limit = 1024 * 1024;
+ QFETCH(int, blockSize);
+ QFETCH(QString, path);
+ QTemporaryFile f;
+ f.setFileTemplate(path);
+ QByteArray block;
+ block.fill('@', blockSize);
+ QBENCHMARK {
+ QVERIFY(f.open());
+ for (qint64 pos = limit - blockSize; pos >= 0; pos -= blockSize) {
+ QVERIFY(f.seek(pos));
+ QVERIFY(f.write(block));
+ }
+ QVERIFY(f.flush());
+ QCOMPARE(f.size(), limit);
+ f.close();
+ }
+}
+
+void tst_qfile::writeFileSequentialWithSeeks_data()
+{
+ writeFileSequential_data();
+}
+
+void tst_qfile::writeFileSequentialWithSeeks()
+{
+ const qint64 limit = 1024 * 1024;
+ QFETCH(int, blockSize);
+ QFETCH(QString, path);
+ QTemporaryFile f;
+ f.setFileTemplate(path);
+ QByteArray block;
+ block.fill('@', blockSize);
+ QBENCHMARK {
+ QVERIFY(f.open());
+ for (qint64 pos = 0; pos < limit; pos += blockSize) {
+ QVERIFY(f.seek(pos));
+ QVERIFY(f.write(block));
+ }
+ QVERIFY(f.flush());
+ QCOMPARE(f.size(), limit);
+ f.close();
+ }
+}
+
QTEST_MAIN(tst_qfile)
#include "main.moc"