diff options
author | Marc Mutz <marc.mutz@qt.io> | 2023-08-08 09:19:49 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@qt.io> | 2023-08-09 23:57:21 +0200 |
commit | 17dad4b88bcdacc144812d0b63664540177cff77 (patch) | |
tree | a4a07c50cce69c994fd89cb9a2a0b46aa59dffb0 /tests/benchmarks/corelib/mimetypes | |
parent | 445c4adc24d76160706fe755e28228114db97bc3 (diff) |
QMimeDatabase benchmark: measure only what it pertinent
Drag the QCOMPARE (which even dynamically allocated a QString
fromLatin1()) out of the QBENCHMARK loop. Testing performance of
QString::fromLatin1() and/or qCompare() is not pertinent to the task
at hand, which, ideally, doesn't involve any memory allocations, so
there's at least the chance that this skewed the result noticably.
Didn't run the benchmark as this was developed on an asan build.
Yes, this breaks comparability with the stone-age measurements
reported in comments there, so sue me.
As a drive-by, replace the fromLatin1() with a u_s UDL.
Pick-to: 6.6 6.5
Change-Id: I9b2a8b2e3596ec9b07c6b4ea369257b1a86e09db
Reviewed-by: Ahmad Samir <a.samirh78@gmail.com>
Reviewed-by: David Faure <david.faure@kdab.com>
Diffstat (limited to 'tests/benchmarks/corelib/mimetypes')
-rw-r--r-- | tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp b/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp index 0711dd9244..bd30c5b812 100644 --- a/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp +++ b/tests/benchmarks/corelib/mimetypes/qmimedatabase/tst_bench_qmimedatabase.cpp @@ -5,6 +5,8 @@ #include <QTest> #include <QMimeDatabase> +using namespace Qt::StringLiterals; + namespace { struct MatchModeInfo { @@ -60,17 +62,17 @@ void tst_QMimeDatabase::inheritsPerformance() QMimeDatabase db; QMimeType mime = db.mimeTypeForName(QString::fromLatin1("text/x-chdr")); QVERIFY(mime.isValid()); + QString match; QBENCHMARK { - QString match; - foreach (const QString &mt, mimeTypes) { + for (const QString &mt : std::as_const(mimeTypes)) { if (mime.inherits(mt)) { match = mt; // of course there would normally be a "break" here, but we're testing worse-case // performance here } } - QCOMPARE(match, QString::fromLatin1("text/plain")); } + QCOMPARE(match, u"text/plain"_s); // Numbers from 2011, in release mode: // KDE 4.7 numbers: 0.21 msec / 494,000 ticks / 568,345 instr. loads per iteration // QMimeBinaryProvider (with Qt 5): 0.16 msec / NA / 416,049 instr. reads per iteration |