diff --git a/tests/benchmarks/corelib/CMakeLists.txt b/tests/benchmarks/corelib/CMakeLists.txt index ea00b02c61a..855e7ee2fa0 100644 --- a/tests/benchmarks/corelib/CMakeLists.txt +++ b/tests/benchmarks/corelib/CMakeLists.txt @@ -11,3 +11,4 @@ add_subdirectory(thread) add_subdirectory(time) add_subdirectory(tools) add_subdirectory(plugin) +add_subdirectory(serialization) diff --git a/tests/benchmarks/corelib/serialization/CMakeLists.txt b/tests/benchmarks/corelib/serialization/CMakeLists.txt new file mode 100644 index 00000000000..98343d7688b --- /dev/null +++ b/tests/benchmarks/corelib/serialization/CMakeLists.txt @@ -0,0 +1,4 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +add_subdirectory(qcborvalue) diff --git a/tests/benchmarks/corelib/serialization/qcborvalue/CMakeLists.txt b/tests/benchmarks/corelib/serialization/qcborvalue/CMakeLists.txt new file mode 100644 index 00000000000..6ada5b983d1 --- /dev/null +++ b/tests/benchmarks/corelib/serialization/qcborvalue/CMakeLists.txt @@ -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 +) diff --git a/tests/benchmarks/corelib/serialization/qcborvalue/tst_bench_qcborvalue.cpp b/tests/benchmarks/corelib/serialization/qcborvalue/tst_bench_qcborvalue.cpp new file mode 100644 index 00000000000..2c606ccafee --- /dev/null +++ b/tests/benchmarks/corelib/serialization/qcborvalue/tst_bench_qcborvalue.cpp @@ -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 +#include + +#include + +template +struct SampleStrings +{ + static constexpr char key[] = "hello"; +}; + +template <> +struct SampleStrings +{ + static constexpr char16_t key[] = u"hello"; +}; + +template <> +struct SampleStrings +{ + static const QChar *const key; +}; +const QChar *const SampleStrings::key = + reinterpret_cast(SampleStrings::key); + +template +constexpr bool hasValueType = false; + +template +constexpr bool hasValueType> = true; + +class tst_QCborValue : public QObject +{ + Q_OBJECT +private: + template + void doKeyLookup(); + +private slots: + void keyLookupLatin1() { doKeyLookup(); } + void keyLookupString() { doKeyLookup(); } + void keyLookupConstCharPtr() { doKeyLookup(); }; +}; + +template +void tst_QCborValue::doKeyLookup() +{ + const QCborMap m{{"hello", "world"}, {1, 2}}; + const QCborValue v = m; + + if constexpr (hasValueType) { + using Char = std::remove_cv_t; + using Strings = SampleStrings; + const Type s(Strings::key); + QBENCHMARK { + const QCborValue r = v[s]; + Q_UNUSED(r); + } + } else { + QBENCHMARK { + const QCborValue r = v[SampleStrings::key]; + Q_UNUSED(r); + } + } +} + +QTEST_MAIN(tst_QCborValue) + +#include "tst_bench_qcborvalue.moc"