tst_bench_QImageReader: add a benchmark for raw QFatoryLoader operations

This is Eirik's QtCore-only QTBUG-114253 reproducer added to the
nearest fitting existing benchmark.

Done-with: Eirik Aavitsland <eirik.aavitsland@qt.io>
Pick-to: 5.15
Task-number: QTBUG-114253
Change-Id: Iba68bedebae908af497267860e2b230db269787e
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
(cherry picked from commit a5bcb41678ad7fe78ad3fac066094f6a614b6906)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 66cd58b2a569ae3423c319a65ab4f198c1c62714)
(cherry picked from commit 1c35f22097a5e6d9234a23567aa3f08992d81770)
This commit is contained in:
Marc Mutz 2023-11-08 17:23:14 +01:00
parent 8ffa2d9dcc
commit 4c0d1383d1
2 changed files with 30 additions and 0 deletions

View File

@ -8,6 +8,7 @@ qt_internal_add_benchmark(tst_bench_qimagereader
SOURCES
tst_bench_qimagereader.cpp
PUBLIC_LIBRARIES
Qt::CorePrivate
Qt::Gui
Qt::Test
)

View File

@ -36,6 +36,7 @@
#include <QImageWriter>
#include <QPixmap>
#include <QtCore/private/qfactoryloader_p.h>
#include <QSet>
#include <QTimer>
@ -55,6 +56,9 @@ public slots:
void initTestCase();
private slots:
void rawFactoryLoader_keyMap();
void rawFactoryLoader_instance();
void readImage_data();
void readImage();
@ -70,6 +74,7 @@ private slots:
private:
QList< QPair<QString, QByteArray> > images; // filename, format
QString prefix;
QFactoryLoader m_loader{QImageIOHandlerFactoryInterface_iid, "/imageformats"};
};
tst_bench_QImageReader::tst_bench_QImageReader()
@ -106,6 +111,30 @@ void tst_bench_QImageReader::initTestCase()
QFAIL("Can't find images directory!");
}
void tst_bench_QImageReader::rawFactoryLoader_keyMap()
{
if (m_loader.keyMap().isEmpty())
QSKIP("No image plugins found.");
QBENCHMARK {
[[maybe_unused]] auto r = m_loader.keyMap();
}
}
void tst_bench_QImageReader::rawFactoryLoader_instance()
{
if (m_loader.keyMap().isEmpty())
QSKIP("No image plugins found.");
const auto numInstances = m_loader.keyMap().uniqueKeys().size();
QBENCHMARK {
for (int i = 0; i < numInstances; ++i)
delete m_loader.instance(i);
}
}
void tst_bench_QImageReader::readImage_data()
{
QTest::addColumn<QString>("fileName");