[clazy] [Bug 361691] Suggestion to turn string into QStringLiteral instead of QLatin1String
Stephen Kelly via KDE Bugzilla
bugzilla_noreply at kde.org
Wed Apr 13 22:10:07 BST 2016
https://bugs.kde.org/show_bug.cgi?id=361691
--- Comment #3 from Stephen Kelly <steveire at gmail.com> ---
I tried to replicate your result unsuccessfully. Do you still have your
benchmark? I tried Qt 5.4.2 and some recent git branch.
#include <QtTest/QTest>
class StringBenchmark : public QObject
{
Q_OBJECT
public:
StringBenchmark(QObject* parent = nullptr) : QObject(parent)
{
for (auto i = 0; i < 10000; ++i)
{
mTestString += QStringLiteral("Long string part %1 --").arg(i);
}
}
private slots:
void containsQStringLiteral() {
QBENCHMARK {
auto result = mTestString.contains(QStringLiteral("Long string part
5555"));
QVERIFY(result);
}
}
void containsQLatin1String() {
QBENCHMARK {
auto result = mTestString.contains(QLatin1String("Long string part
5555"));
QVERIFY(result);
}
}
void indexOfQStringLiteral() {
QBENCHMARK {
auto result = mTestString.indexOf(QStringLiteral("Long string part
5555"));
QCOMPARE(result, 132210);
}
}
void indexOfQLatin1String() {
QBENCHMARK {
auto result = mTestString.indexOf(QLatin1String("Long string part
5555"));
QCOMPARE(result, 132210);
}
}
private:
QString mTestString;
};
QTEST_MAIN(StringBenchmark)
#include "tester.moc"
********* Start testing of StringBenchmark *********
Config: Using QtTest library 5.8.0, Qt 5.8.0 (x86_64-little_endian-lp64 shared
(dynamic) release build; by GCC 5.2.1 20151010)
PASS : StringBenchmark::initTestCase()
PASS : StringBenchmark::containsQStringLiteral()
RESULT : StringBenchmark::containsQStringLiteral():
0.038 msecs per iteration (total: 79, iterations: 2048)
PASS : StringBenchmark::containsQLatin1String()
RESULT : StringBenchmark::containsQLatin1String():
0.040 msecs per iteration (total: 82, iterations: 2048)
PASS : StringBenchmark::indexOfQStringLiteral()
RESULT : StringBenchmark::indexOfQStringLiteral():
0.038 msecs per iteration (total: 78, iterations: 2048)
PASS : StringBenchmark::indexOfQLatin1String()
RESULT : StringBenchmark::indexOfQLatin1String():
0.038 msecs per iteration (total: 78, iterations: 2048)
PASS : StringBenchmark::cleanupTestCase()
Totals: 6 passed, 0 failed, 0 skipped, 0 blacklisted, 1301ms
********* Finished testing of StringBenchmark *********
--
You are receiving this mail because:
You are the assignee for the bug.
More information about the Unassigned-bugs
mailing list