QCborValue: add benchmark for operator[]
In order to test the impact of migration to QASV. Task-number: QTBUG-101707 Pick-to: 6.6 6.5 6.2 Change-Id: I17f84ca98fc87d89bb4cd6ad98c8a12aecd315ee Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
parent
9334947d36
commit
516d828f24
@ -11,3 +11,4 @@ add_subdirectory(thread)
|
||||
add_subdirectory(time)
|
||||
add_subdirectory(tools)
|
||||
add_subdirectory(plugin)
|
||||
add_subdirectory(serialization)
|
||||
|
4
tests/benchmarks/corelib/serialization/CMakeLists.txt
Normal file
4
tests/benchmarks/corelib/serialization/CMakeLists.txt
Normal file
@ -0,0 +1,4 @@
|
||||
# Copyright (C) 2023 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
add_subdirectory(qcborvalue)
|
@ -0,0 +1,10 @@
|
||||
# Copyright (C) 2023 The Qt Company Ltd.
|
||||
# SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
qt_internal_add_benchmark(tst_bench_qcborvalue
|
||||
SOURCES
|
||||
tst_bench_qcborvalue.cpp
|
||||
LIBRARIES
|
||||
Qt::Core
|
||||
Qt::Test
|
||||
)
|
@ -0,0 +1,72 @@
|
||||
// Copyright (C) 2023 The Qt Company Ltd.
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
||||
|
||||
#include <QCborMap>
|
||||
#include <QCborValue>
|
||||
|
||||
#include <QTest>
|
||||
|
||||
template <typename Char>
|
||||
struct SampleStrings
|
||||
{
|
||||
static constexpr char key[] = "hello";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct SampleStrings<char16_t>
|
||||
{
|
||||
static constexpr char16_t key[] = u"hello";
|
||||
};
|
||||
|
||||
template <>
|
||||
struct SampleStrings<QChar>
|
||||
{
|
||||
static const QChar *const key;
|
||||
};
|
||||
const QChar *const SampleStrings<QChar>::key =
|
||||
reinterpret_cast<const QChar *>(SampleStrings<char16_t>::key);
|
||||
|
||||
template <typename T, typename = void>
|
||||
constexpr bool hasValueType = false;
|
||||
|
||||
template <typename T>
|
||||
constexpr bool hasValueType<T, std::void_t<typename T::value_type>> = true;
|
||||
|
||||
class tst_QCborValue : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
private:
|
||||
template <typename Type>
|
||||
void doKeyLookup();
|
||||
|
||||
private slots:
|
||||
void keyLookupLatin1() { doKeyLookup<QLatin1StringView>(); }
|
||||
void keyLookupString() { doKeyLookup<QString>(); }
|
||||
void keyLookupConstCharPtr() { doKeyLookup<char>(); };
|
||||
};
|
||||
|
||||
template <typename Type>
|
||||
void tst_QCborValue::doKeyLookup()
|
||||
{
|
||||
const QCborMap m{{"hello", "world"}, {1, 2}};
|
||||
const QCborValue v = m;
|
||||
|
||||
if constexpr (hasValueType<Type>) {
|
||||
using Char = std::remove_cv_t<typename Type::value_type>;
|
||||
using Strings = SampleStrings<Char>;
|
||||
const Type s(Strings::key);
|
||||
QBENCHMARK {
|
||||
const QCborValue r = v[s];
|
||||
Q_UNUSED(r);
|
||||
}
|
||||
} else {
|
||||
QBENCHMARK {
|
||||
const QCborValue r = v[SampleStrings<Type>::key];
|
||||
Q_UNUSED(r);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
QTEST_MAIN(tst_QCborValue)
|
||||
|
||||
#include "tst_bench_qcborvalue.moc"
|
Loading…
Reference in New Issue
Block a user