summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2022-06-02 20:22:01 +0200
committerMarc Mutz <marc.mutz@qt.io>2022-06-22 01:38:12 +0000
commit32925d0a85b13d2a8032e580db544af5cdfecf8b (patch)
tree25771561297698fbcc40e175a505b451b7e75523 /tests/benchmarks
parent06f21a387069fe02d6e97600fc445a3c71b0fb82 (diff)
tst_tostring: add benchmarks for QCOMPARE vs. QCOMPARE_EQ
There's currently no statistically-significant difference between the two, due to a huge pessimistion in QTestLib where every QCOMPARE* and QVERIFY writes 1KiB of data onto the stack before doing anything else, so I'm not reporting numbers in this commit message. Pick-to: 6.4 Task-number: QTBUG-98873 Task-number: QTBUG-98874 Change-Id: I233878596f0a8fe6b96360adb839fecd72c398a2 Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/testlib/tostring/tst_tostring.cpp55
1 files changed, 55 insertions, 0 deletions
diff --git a/tests/benchmarks/testlib/tostring/tst_tostring.cpp b/tests/benchmarks/testlib/tostring/tst_tostring.cpp
index 913a0337c6..c72ec220b1 100644
--- a/tests/benchmarks/testlib/tostring/tst_tostring.cpp
+++ b/tests/benchmarks/testlib/tostring/tst_tostring.cpp
@@ -25,6 +25,36 @@ private slots:
void quint64Tst() { numeric<quint64>(); }
void qint64Tst_data() { numeric_data<qint64>(); }
void qint64Tst() { numeric<qint64>(); }
+
+private:
+ template <typename T> void compare();
+ template <typename T> void compare_eq();
+
+private slots:
+ void floatCompare_data() { numeric_data<float>(); }
+ void floatCompare() { compare<float>(); }
+ void floatCompareEq_data() { numeric_data<float>(); }
+ void floatCompareEq() { compare_eq<float>(); }
+ void doubleCompare_data() { numeric_data<double>(); }
+ void doubleCompare() { compare<double>(); }
+ void doubleCompareEq_data() { numeric_data<double>(); }
+ void doubleCompareEq() { compare_eq<double>(); }
+ void intCompare_data() { numeric_data<int>(); }
+ void intCompare() { compare<int>(); }
+ void intCompareEq_data() { numeric_data<int>(); }
+ void intCompareEq() { compare_eq<int>(); }
+ void unsignedCompare_data() { numeric_data<unsigned>(); }
+ void unsignedCompare() { compare<unsigned>(); }
+ void unsignedCompareEq_data() { numeric_data<unsigned>(); }
+ void unsignedCompareEq() { compare_eq<unsigned>(); }
+ void quint64Compare_data() { numeric_data<quint64>(); }
+ void quint64Compare() { compare<quint64>(); }
+ void quint64CompareEq_data() { numeric_data<quint64>(); }
+ void quint64CompareEq() { compare_eq<quint64>(); }
+ void qint64Compare_data() { numeric_data<qint64>(); }
+ void qint64Compare() { compare<qint64>(); }
+ void qint64CompareEq_data() { numeric_data<qint64>(); }
+ void qint64CompareEq() { compare_eq<qint64>(); }
};
template <typename T>
@@ -75,5 +105,30 @@ void tst_toString::numeric()
}
}
+template <typename T>
+void tst_toString::compare()
+{
+ QFETCH(T, datum);
+
+ QBENCHMARK {
+ QCOMPARE(datum, datum);
+ }
+}
+
+template <typename T>
+void tst_toString::compare_eq()
+{
+ QFETCH(T, datum);
+
+ if constexpr (std::numeric_limits<T>::has_quiet_NaN) {
+ if (qIsNaN(datum))
+ QSKIP("Unlike QCOMPARE, QCOMPARE_EQ doesn't handle NaN specially");
+ }
+
+ QBENCHMARK {
+ QCOMPARE_EQ(datum, datum);
+ }
+}
+
QTEST_MAIN(tst_toString)
#include "tst_tostring.moc"