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. Change-Id: I9b2a8b2e3596ec9b07c6b4ea369257b1a86e09db Reviewed-by: Ahmad Samir <a.samirh78@gmail.com> Reviewed-by: David Faure <david.faure@kdab.com> (cherry picked from commit 17dad4b88bcdacc144812d0b63664540177cff77) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
0f272af5c8
commit
194848c5fd
@ -5,6 +5,8 @@
|
|||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <QMimeDatabase>
|
#include <QMimeDatabase>
|
||||||
|
|
||||||
|
using namespace Qt::StringLiterals;
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
struct MatchModeInfo
|
struct MatchModeInfo
|
||||||
{
|
{
|
||||||
@ -60,17 +62,17 @@ void tst_QMimeDatabase::inheritsPerformance()
|
|||||||
QMimeDatabase db;
|
QMimeDatabase db;
|
||||||
QMimeType mime = db.mimeTypeForName(QString::fromLatin1("text/x-chdr"));
|
QMimeType mime = db.mimeTypeForName(QString::fromLatin1("text/x-chdr"));
|
||||||
QVERIFY(mime.isValid());
|
QVERIFY(mime.isValid());
|
||||||
|
QString match;
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
QString match;
|
for (const QString &mt : std::as_const(mimeTypes)) {
|
||||||
foreach (const QString &mt, mimeTypes) {
|
|
||||||
if (mime.inherits(mt)) {
|
if (mime.inherits(mt)) {
|
||||||
match = mt;
|
match = mt;
|
||||||
// of course there would normally be a "break" here, but we're testing worse-case
|
// of course there would normally be a "break" here, but we're testing worse-case
|
||||||
// performance here
|
// performance here
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QCOMPARE(match, QString::fromLatin1("text/plain"));
|
|
||||||
}
|
}
|
||||||
|
QCOMPARE(match, u"text/plain"_s);
|
||||||
// Numbers from 2011, in release mode:
|
// Numbers from 2011, in release mode:
|
||||||
// KDE 4.7 numbers: 0.21 msec / 494,000 ticks / 568,345 instr. loads per iteration
|
// 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
|
// QMimeBinaryProvider (with Qt 5): 0.16 msec / NA / 416,049 instr. reads per iteration
|
||||||
|
Loading…
x
Reference in New Issue
Block a user