From 6658ccf5a1a0ef298fde1884e449c062faf011e3 Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 5 Sep 2023 17:34:52 +0200 Subject: [PATCH] Add QCborValue(StringLike) constructor benchmark ... to test the impact of migrating the underlying implementation to QAnyStringView. As a drive-by: use [[maybe_unused]] instead of Q_UNUSED in the benchmark for operator[]. Task-number: QTBUG-101707 Pick-to: 6.6 6.5 6.2 Change-Id: I4bae7deadbe9bbd6f267364d78e94ea4541c1339 Reviewed-by: Marc Mutz --- .../qcborvalue/tst_bench_qcborvalue.cpp | 31 ++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/tests/benchmarks/corelib/serialization/qcborvalue/tst_bench_qcborvalue.cpp b/tests/benchmarks/corelib/serialization/qcborvalue/tst_bench_qcborvalue.cpp index 2c606ccafe..3400965176 100644 --- a/tests/benchmarks/corelib/serialization/qcborvalue/tst_bench_qcborvalue.cpp +++ b/tests/benchmarks/corelib/serialization/qcborvalue/tst_bench_qcborvalue.cpp @@ -39,10 +39,18 @@ private: template void doKeyLookup(); + template + void doConstruct(); + private slots: void keyLookupLatin1() { doKeyLookup(); } void keyLookupString() { doKeyLookup(); } void keyLookupConstCharPtr() { doKeyLookup(); }; + + void constructLatin1() { doConstruct(); } + void constructString() { doConstruct(); } + void constructStringView() { doConstruct(); } + void constructConstCharPtr() { doConstruct(); } }; template @@ -56,13 +64,28 @@ void tst_QCborValue::doKeyLookup() using Strings = SampleStrings; const Type s(Strings::key); QBENCHMARK { - const QCborValue r = v[s]; - Q_UNUSED(r); + [[maybe_unused]] const QCborValue r = v[s]; } } else { QBENCHMARK { - const QCborValue r = v[SampleStrings::key]; - Q_UNUSED(r); + [[maybe_unused]] const QCborValue r = v[SampleStrings::key]; + } + } +} + +template +void tst_QCborValue::doConstruct() +{ + if constexpr (hasValueType) { + using Char = std::remove_cv_t; + using Strings = SampleStrings; + const Type s(Strings::key); + QBENCHMARK { + [[maybe_unused]] const auto v = QCborValue{s}; + } + } else { + QBENCHMARK { + [[maybe_unused]] const auto v = QCborValue{SampleStrings::key}; } } }