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 <marc.mutz@qt.io>
This commit is contained in:
Ivan Solovev 2023-09-05 17:34:52 +02:00
parent f3d074b6b0
commit 6658ccf5a1

View File

@ -39,10 +39,18 @@ private:
template <typename Type> template <typename Type>
void doKeyLookup(); void doKeyLookup();
template <typename Type>
void doConstruct();
private slots: private slots:
void keyLookupLatin1() { doKeyLookup<QLatin1StringView>(); } void keyLookupLatin1() { doKeyLookup<QLatin1StringView>(); }
void keyLookupString() { doKeyLookup<QString>(); } void keyLookupString() { doKeyLookup<QString>(); }
void keyLookupConstCharPtr() { doKeyLookup<char>(); }; void keyLookupConstCharPtr() { doKeyLookup<char>(); };
void constructLatin1() { doConstruct<QLatin1StringView>(); }
void constructString() { doConstruct<QString>(); }
void constructStringView() { doConstruct<QStringView>(); }
void constructConstCharPtr() { doConstruct<char>(); }
}; };
template <typename Type> template <typename Type>
@ -56,13 +64,28 @@ void tst_QCborValue::doKeyLookup()
using Strings = SampleStrings<Char>; using Strings = SampleStrings<Char>;
const Type s(Strings::key); const Type s(Strings::key);
QBENCHMARK { QBENCHMARK {
const QCborValue r = v[s]; [[maybe_unused]] const QCborValue r = v[s];
Q_UNUSED(r);
} }
} else { } else {
QBENCHMARK { QBENCHMARK {
const QCborValue r = v[SampleStrings<Type>::key]; [[maybe_unused]] const QCborValue r = v[SampleStrings<Type>::key];
Q_UNUSED(r); }
}
}
template<typename Type>
void tst_QCborValue::doConstruct()
{
if constexpr (hasValueType<Type>) {
using Char = std::remove_cv_t<typename Type::value_type>;
using Strings = SampleStrings<Char>;
const Type s(Strings::key);
QBENCHMARK {
[[maybe_unused]] const auto v = QCborValue{s};
}
} else {
QBENCHMARK {
[[maybe_unused]] const auto v = QCborValue{SampleStrings<Type>::key};
} }
} }
} }