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: 6.6 6.5 6.2 5.15
Task-number: QTBUG-114253
Change-Id: Iba68bedebae908af497267860e2b230db269787e
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
This commit is contained in:
Marc Mutz 2023-11-08 17:23:14 +01:00
parent 6c60117d01
commit a5bcb41678
2 changed files with 30 additions and 0 deletions

View File

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

View File

@ -11,6 +11,7 @@
#include <QImageWriter>
#include <QPixmap>
#include <QtCore/private/qfactoryloader_p.h>
#include <QSet>
#include <QTimer>
@ -30,6 +31,9 @@ public slots:
void initTestCase();
private slots:
void rawFactoryLoader_keyMap();
void rawFactoryLoader_instance();
void readImage_data();
void readImage();
@ -45,6 +49,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()
@ -81,6 +86,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");