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>
This commit is contained in:
parent
445c4adc24
commit
17dad4b88b
@ -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
|
||||
|
Loading…
x
Reference in New Issue
Block a user