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 <axel.spoerl@qt.io>
This commit is contained in:
parent
83ff179f85
commit
0345b46ac7
@ -3,3 +3,4 @@
|
||||
|
||||
add_subdirectory(qguimetatype)
|
||||
add_subdirectory(qguivariant)
|
||||
add_subdirectory(qkeysequence)
|
||||
|
14
tests/benchmarks/gui/kernel/qkeysequence/CMakeLists.txt
Normal file
14
tests/benchmarks/gui/kernel/qkeysequence/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# Copyright (C) 2025 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
||||
# 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
|
||||
)
|
@ -0,0 +1,49 @@
|
||||
// Copyright (C) 2025 Vlad Zahorodnii <vlad.zahorodnii@kde.org>
|
||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||
|
||||
#include <qtest.h>
|
||||
#include <QtGui/qkeysequence.h>
|
||||
|
||||
class tst_QKeySequence : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
private slots:
|
||||
void fromString_data();
|
||||
void fromString();
|
||||
};
|
||||
|
||||
void tst_QKeySequence::fromString_data()
|
||||
{
|
||||
QTest::addColumn<QString>("text");
|
||||
QTest::addColumn<QKeySequence::SequenceFormat>("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"
|
Loading…
x
Reference in New Issue
Block a user