summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/text
diff options
context:
space:
mode:
authorEdward Welbourne <edward.welbourne@qt.io>2021-08-25 17:52:38 +0200
committerEdward Welbourne <edward.welbourne@qt.io>2021-08-27 18:44:50 +0200
commit9935dfe289a2982ae336eb83b50ffdcec6d2e88a (patch)
tree41b8f0c86e51e101baa8fd7672d31346b4a99390 /tests/benchmarks/corelib/text
parent8043a1a75aedc89af53859d187632fab7ed83f46 (diff)
New QByteArray::toU?LongLong() benchmark
Change-Id: Ic0581dd5625f9b2750646c73dc80d89741d97a1d Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'tests/benchmarks/corelib/text')
-rw-r--r--tests/benchmarks/corelib/text/qbytearray/main.cpp91
1 files changed, 90 insertions, 1 deletions
diff --git a/tests/benchmarks/corelib/text/qbytearray/main.cpp b/tests/benchmarks/corelib/text/qbytearray/main.cpp
index 9a824ff9e0..43151041d0 100644
--- a/tests/benchmarks/corelib/text/qbytearray/main.cpp
+++ b/tests/benchmarks/corelib/text/qbytearray/main.cpp
@@ -1,6 +1,6 @@
/****************************************************************************
**
-** Copyright (C) 2016 The Qt Company Ltd.
+** Copyright (C) 2021 The Qt Company Ltd.
** Copyright (C) 2016 Intel Corporation.
** Contact: https://www.qt.io/licensing/
**
@@ -32,6 +32,7 @@
#include <QString>
#include <qtest.h>
+#include <limits>
class tst_qbytearray : public QObject
@@ -43,6 +44,11 @@ private slots:
void append();
void append_data();
+ void toLongLong_data();
+ void toLongLong();
+ void toULongLong_data();
+ void toULongLong();
+
void latin1Uppercasing_qt54();
void latin1Uppercasing_xlate();
void latin1Uppercasing_xlate_checked();
@@ -86,6 +92,89 @@ void tst_qbytearray::append()
}
}
+static QByteArray decNext(QByteArray &&big)
+{
+ // Increments a decimal digit-string (ignoring sign, so decrements if
+ // negative); only intended for taking a boundary value just out of range,
+ // so big is never a string of only 9s (that'd be one less than a power of
+ // ten, which cannot be a power of two, as odd, or one less than one, as the
+ // power of ten isn't a power of two).
+ int i = big.size() - 1;
+ while (big.at(i) == '9')
+ big[i--] = '0';
+ big[i] += 1;
+ return big;
+}
+
+void tst_qbytearray::toLongLong_data()
+{
+ QTest::addColumn<QByteArray>("text");
+ QTest::addColumn<bool>("good");
+ QTest::addColumn<qlonglong>("number");
+#define ROW(n) QTest::newRow(#n) << QByteArray(#n) << true << n ## LL
+ ROW(0);
+ ROW(1);
+ ROW(-1);
+ ROW(17);
+ ROW(-17);
+ ROW(1234567890);
+ ROW(-1234567890);
+#undef ROW
+ using LL = std::numeric_limits<qlonglong>;
+ QTest::newRow("min") << QByteArray::number(LL::min()) << true << LL::min();
+ QTest::newRow("min-1") << decNext(QByteArray::number(LL::min())) << false << 0LL;
+ QTest::newRow("max") << QByteArray::number(LL::max()) << true << LL::max();
+ QTest::newRow("max+1") << decNext(QByteArray::number(LL::max())) << false << 0LL;
+}
+
+void tst_qbytearray::toLongLong()
+{
+ QFETCH(QByteArray, text);
+ QFETCH(bool, good);
+ QFETCH(qlonglong, number);
+
+ qlonglong actual = 0;
+ bool ok;
+ QBENCHMARK {
+ actual = text.toLongLong(&ok);
+ }
+ QCOMPARE(actual, number);
+ QCOMPARE(ok, good);
+}
+
+void tst_qbytearray::toULongLong_data()
+{
+ QTest::addColumn<QByteArray>("text");
+ QTest::addColumn<bool>("good");
+ QTest::addColumn<qulonglong>("number");
+#define ROW(n) \
+ QTest::newRow(#n) << QByteArray(#n) << true << n ## ULL; \
+ QTest::newRow("-" #n) << QByteArray("-" #n) << false << 0ULL
+ ROW(0);
+ ROW(1);
+ ROW(17);
+ ROW(1234567890);
+#undef ROW
+ using ULL = std::numeric_limits<qulonglong>;
+ QTest::newRow("max") << QByteArray::number(ULL::max()) << true << ULL::max();
+ QTest::newRow("max+1") << decNext(QByteArray::number(ULL::max())) << false << 0ULL;
+}
+
+void tst_qbytearray::toULongLong()
+{
+ QFETCH(QByteArray, text);
+ QFETCH(bool, good);
+ QFETCH(qulonglong, number);
+
+ qulonglong actual = 0;
+ bool ok;
+ QBENCHMARK {
+ actual = text.toULongLong(&ok);
+ }
+ QCOMPARE(actual, number);
+ QCOMPARE(ok, good);
+}
+
void tst_qbytearray::latin1Uppercasing_qt54()
{
QByteArray s = sourcecode;