From f1d40ca5e9b635e565bcaba5fb2a95f065478b51 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 5 Jul 2021 14:27:34 +0200 Subject: [PATCH] Unify and clean up two identical tst_qfile::*_data() functions Convert newRow() to addRow() to simplify formatting, use a ranged-for iteration, take out a common factor of 1024, use QByteArray instead of roundtripping ASCII via Unicode, and break some long lines. Change-Id: I052730a71fb74f40a0dbd0695dcc286bc39896fb Reviewed-by: Jason McDonald Reviewed-by: Andreas Buhr --- tests/benchmarks/corelib/io/qfile/main.cpp | 98 +++++++++------------- 1 file changed, 41 insertions(+), 57 deletions(-) diff --git a/tests/benchmarks/corelib/io/qfile/main.cpp b/tests/benchmarks/corelib/io/qfile/main.cpp index 1a4000772a..d24189aec0 100644 --- a/tests/benchmarks/corelib/io/qfile/main.cpp +++ b/tests/benchmarks/corelib/io/qfile/main.cpp @@ -108,9 +108,8 @@ private slots: void readBigFile_Win32(); private: - void readBigFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b); + void readFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b); void readBigFile(); - void readSmallFiles_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b); void readSmallFiles(); void createFile(); void fillFile(int factor=FACTOR); @@ -166,6 +165,30 @@ void tst_qfile::cleanupTestCase() { } +void tst_qfile::readFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, + QIODevice::OpenModeFlag b) +{ + QTest::addColumn("testType"); + QTest::addColumn("blockSize"); + QTest::addColumn("textMode"); + QTest::addColumn("bufferedMode"); + + QByteArray flagstring; + if (t & QIODevice::Text) + flagstring += "textMode "; + if (b & QIODevice::Unbuffered) + flagstring += "unbuffered "; + if (flagstring.isEmpty()) + flagstring = "none"; + + const int kbs[] = {1, 2, 8, 16, 32, 512}; + for (int kb : kbs) { + const int size = 1024 * kb; + QTest::addRow("BS: %d, Flags: %s", size, flagstring.constData()) + << type << size << t << b; + } +} + void tst_qfile::readBigFile_QFile() { readBigFile(); } void tst_qfile::readBigFile_QFSFileEngine() { @@ -179,10 +202,10 @@ void tst_qfile::readBigFile_Win32() { readBigFile(); } void tst_qfile::readBigFile_QFile_data() { - readBigFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); - readBigFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); - readBigFile_data(QFileBenchmark, QIODevice::Text, QIODevice::NotOpen); - readBigFile_data(QFileBenchmark, QIODevice::Text, QIODevice::Unbuffered); + readFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); + readFile_data(QFileBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); + readFile_data(QFileBenchmark, QIODevice::Text, QIODevice::NotOpen); + readFile_data(QFileBenchmark, QIODevice::Text, QIODevice::Unbuffered); } @@ -190,8 +213,8 @@ void tst_qfile::readBigFile_QFSFileEngine_data() { #ifdef QT_BUILD_INTERNAL // Support for buffering dropped at 5.10, so only test Unbuffered - readBigFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); - readBigFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered); + readFile_data(QFSFileEngineBenchmark, QIODevice::NotOpen, QIODevice::Unbuffered); + readFile_data(QFSFileEngineBenchmark, QIODevice::Text, QIODevice::Unbuffered); #else QSKIP("This test requires -developer-build."); #endif @@ -199,37 +222,18 @@ void tst_qfile::readBigFile_QFSFileEngine_data() void tst_qfile::readBigFile_posix_data() { - readBigFile_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); + readFile_data(PosixBenchmark, QIODevice::NotOpen, QIODevice::NotOpen); } void tst_qfile::readBigFile_Win32_data() { #ifdef Q_OS_WIN - readBigFile_data(Win32Benchmark, QIODevice::NotOpen, QIODevice::NotOpen); + readFile_data(Win32Benchmark, QIODevice::NotOpen, QIODevice::NotOpen); #else QSKIP("This is Windows only benchmark."); #endif } -void tst_qfile::readBigFile_data(BenchmarkType type, QIODevice::OpenModeFlag t, QIODevice::OpenModeFlag b) -{ - QTest::addColumn("testType"); - QTest::addColumn("blockSize"); - QTest::addColumn("textMode"); - QTest::addColumn("bufferedMode"); - - const int bs[] = {1024, 1024*2, 1024*8, 1024*16, 1024*32,1024*512}; - int bs_entries = sizeof(bs)/sizeof(const int); - - QString flagstring; - if (t & QIODevice::Text) flagstring += "textMode "; - if (b & QIODevice::Unbuffered) flagstring += "unbuffered "; - if (flagstring.isEmpty()) flagstring = "none"; - - for (int i=0; i("testType"); - QTest::addColumn("blockSize"); - QTest::addColumn("textMode"); - QTest::addColumn("bufferedMode"); - - const int bs[] = {1024, 1024*2, 1024*8, 1024*16, 1024*32,1024*512}; - int bs_entries = sizeof(bs)/sizeof(const int); - - QString flagstring; - if (t & QIODevice::Text) flagstring += "textMode "; - if (b & QIODevice::Unbuffered) flagstring += "unbuffered "; - if (flagstring.isEmpty()) flagstring = "none"; - - for (int i=0; i