Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
6.7.0
-
None
-
Linux
-
-
eeb6f0337 (dev), 7200f8638 (dev), 726379c58 (dev), 7886d0adb (dev)
Description
In the benchmark, std::ranges::search is faster than QByteArrayView::contains when comparing the same source and the same target.
********* Start testing of SpeedTest ********* Config: Using QtTest library 6.7.0, Qt 6.7.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 13.2.1 20240206 [revision 67ac78caf31f7cb3202177e6428a46d829b70f23]), opensuse-tumbleweed 20240428 QCRITICAL: SpeedTest::initTestCase() "%1" PASS : SpeedTest::initTestCase() PASS : SpeedTest::test_bytearray() RESULT : SpeedTest::test_bytearray(): 8,609 nsecs per iteration (total: 8,609, iterations: 1) 1,307 CPU cycles per iteration, 152 MHz (total: 1,307, iterations: 1) 1,171 instructions per iteration, 0.896 instr/cycle (total: 1,171, iterations: 1) 255 branch instructions per iteration, 29.6 M/sec (total: 255, iterations: 1) PASS : SpeedTest::test_ranges_utf8view() RESULT : SpeedTest::test_ranges_utf8view(): 10,882 nsecs per iteration (total: 10,882, iterations: 1) 718 CPU cycles per iteration, 66 MHz (total: 718, iterations: 1) 977 instructions per iteration, 1.361 instr/cycle (total: 977, iterations: 1) 230 branch instructions per iteration, 21.1 M/sec (total: 230, iterations: 1) PASS : SpeedTest::test_ranges_bytearrayview() RESULT : SpeedTest::test_ranges_bytearrayview(): 6,965 nsecs per iteration (total: 6,965, iterations: 1) 655 CPU cycles per iteration, 94 MHz (total: 655, iterations: 1) 977 instructions per iteration, 1.492 instr/cycle (total: 977, iterations: 1) 230 branch instructions per iteration, 33 M/sec (total: 230, iterations: 1) PASS : SpeedTest::cleanupTestCase() Totals: 5 passed, 0 failed, 0 skipped, 0 blacklisted, 73ms ********* Finished testing of SpeedTest *********
#pragma GCC push_options #pragma GCC optimize("O2") #include <algorithm> #include <QTest> #include <QString> #include <QProcess> using namespace Qt::StringLiterals; using namespace std::string_view_literals; using namespace std::chrono_literals; const char *untranslatedText(const char *input) { QByteArray output = QByteArray("abcdefg……") + input; return output.constData(); } class SpeedTest : public QObject { Q_OBJECT private Q_SLOTS: void initTestCase(); void test_bytearray(); void test_ranges_utf8view(); void test_ranges_bytearrayview(); private: bool result = false; QByteArray input; }; QTEST_MAIN(SpeedTest) void SpeedTest::initTestCase() { QProcess p; p.start(u"echo"_s, {u"-n"_s, u"%1"_s}); p.waitForFinished(); input = p.readAllStandardOutput(); QVERIFY(!input.isEmpty()); } void SpeedTest::test_bytearray() { QBENCHMARK { result = QByteArrayView(untranslatedText(input)).contains(QByteArrayView("%1")); } QVERIFY(result); } void SpeedTest::test_ranges_utf8view() { QBENCHMARK { QUtf8StringView text{untranslatedText(input)}; result = !std::ranges::search(text, QUtf8StringView("%1")).empty(); } QVERIFY(result); } void SpeedTest::test_ranges_bytearrayview() { QBENCHMARK { QByteArrayView text(untranslatedText(input)); result = !std::ranges::search(text, QByteArrayView("%1")).empty(); } QVERIFY(result); } #include "main.moc" #pragma GCC pop_options
Attachments
For Gerrit Dashboard: QTBUG-125283 | ||||||
---|---|---|---|---|---|---|
# | Subject | Branch | Project | Status | CR | V |
560904,3 | QByteArray: de-duplicate the find-one-char function | dev | qt/qtbase | Status: MERGED | +2 | 0 |
560905,3 | QByteArray: deduplicate QtPrivate::findByteArray() and qFindByteArray() | dev | qt/qtbase | Status: MERGED | +2 | 0 |
560906,3 | QByteArrayView: move up the call to 1-char findByteArray() | dev | qt/qtbase | Status: MERGED | +2 | 0 |
560907,3 | QByteArray: inline the REHASH macro into the code | dev | qt/qtbase | Status: MERGED | +2 | 0 |