From 0345b46ac76d50f408f3b9a949e7921a1774e50f Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Thu, 16 Jan 2025 02:22:04 +0200 Subject: [PATCH] Add QKeySequence::fromString() benchmark An application may need to load shortcuts from the settings at startup, so QKeySequence::fromString() should be fast enough if there is a lot of shortcuts. This change adds a QKeySequence::fromString() benchmark so one could get partial insight in its performance. Change-Id: I9e15c0e9a199787189d5076a41154f127d2930a3 Reviewed-by: Axel Spoerl --- tests/benchmarks/gui/kernel/CMakeLists.txt | 1 + .../gui/kernel/qkeysequence/CMakeLists.txt | 14 ++++++ .../kernel/qkeysequence/tst_qkeysequence.cpp | 49 +++++++++++++++++++ 3 files changed, 64 insertions(+) create mode 100644 tests/benchmarks/gui/kernel/qkeysequence/CMakeLists.txt create mode 100644 tests/benchmarks/gui/kernel/qkeysequence/tst_qkeysequence.cpp diff --git a/tests/benchmarks/gui/kernel/CMakeLists.txt b/tests/benchmarks/gui/kernel/CMakeLists.txt index 1f79c7d99bc..9d5e480faa9 100644 --- a/tests/benchmarks/gui/kernel/CMakeLists.txt +++ b/tests/benchmarks/gui/kernel/CMakeLists.txt @@ -3,3 +3,4 @@ add_subdirectory(qguimetatype) add_subdirectory(qguivariant) +add_subdirectory(qkeysequence) diff --git a/tests/benchmarks/gui/kernel/qkeysequence/CMakeLists.txt b/tests/benchmarks/gui/kernel/qkeysequence/CMakeLists.txt new file mode 100644 index 00000000000..44332343d2e --- /dev/null +++ b/tests/benchmarks/gui/kernel/qkeysequence/CMakeLists.txt @@ -0,0 +1,14 @@ +# Copyright (C) 2025 Vlad Zahorodnii +# SPDX-License-Identifier: BSD-3-Clause + +##################################################################### +## tst_bench_qkeysequence Binary: +##################################################################### + +qt_internal_add_benchmark(tst_bench_qkeysequence + SOURCES + tst_qkeysequence.cpp + LIBRARIES + Qt::Gui + Qt::Test +) diff --git a/tests/benchmarks/gui/kernel/qkeysequence/tst_qkeysequence.cpp b/tests/benchmarks/gui/kernel/qkeysequence/tst_qkeysequence.cpp new file mode 100644 index 00000000000..2ab9120d94c --- /dev/null +++ b/tests/benchmarks/gui/kernel/qkeysequence/tst_qkeysequence.cpp @@ -0,0 +1,49 @@ +// Copyright (C) 2025 Vlad Zahorodnii +// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only + +#include +#include + +class tst_QKeySequence : public QObject +{ + Q_OBJECT + +private slots: + void fromString_data(); + void fromString(); +}; + +void tst_QKeySequence::fromString_data() +{ + QTest::addColumn("text"); + QTest::addColumn("format"); + + QTest::newRow("empty (portable)") << QString() << QKeySequence::PortableText; + QTest::newRow("empty (native)") << QString() << QKeySequence::NativeText; + + QTest::newRow("invalid (portable)") << QStringLiteral("pizza") << QKeySequence::PortableText; + QTest::newRow("invalid (native)") << QStringLiteral("pizza") << QKeySequence::NativeText; + + QTest::newRow("F (portable)") << QStringLiteral("F") << QKeySequence::PortableText; + QTest::newRow("F (native)") << QStringLiteral("F") << QKeySequence::NativeText; + + QTest::newRow("Ctrl+F (portable)") << QStringLiteral("Ctrl+F") << QKeySequence::PortableText; + QTest::newRow("Ctrl+F (native)") << QStringLiteral("Ctrl+F") << QKeySequence::NativeText; + + QTest::newRow("Meta+Ctrl+Alt+Shift+F (portable)") << QStringLiteral("Meta+Ctrl+Alt+Shift+F") << QKeySequence::PortableText; + QTest::newRow("Meta+Ctrl+Alt+Shift+F (native)") << QStringLiteral("Meta+Ctrl+Alt+Shift+F") << QKeySequence::NativeText; +} + +void tst_QKeySequence::fromString() +{ + QFETCH(QString, text); + QFETCH(QKeySequence::SequenceFormat, format); + + QBENCHMARK { + auto sequence = QKeySequence::fromString(text, format); + Q_UNUSED(sequence) + } +} + +QTEST_MAIN(tst_QKeySequence) +#include "tst_qkeysequence.moc"