Commit 5db2a493 authored by Adam Reichold's avatar Adam Reichold

Add rendering benchmark using QtTest framework.

parent fc27d3d8
Pipeline #7094 failed with stage
in 9 minutes and 46 seconds
......@@ -22,7 +22,7 @@ macro(QT5_ADD_SIMPLETEST exe source)
${source}
)
poppler_add_test(${exe} BUILD_QT5_TESTS ${${test_name}_SOURCES})
target_link_libraries(${exe} poppler-qt5 ${Qt5Widgets_LIBRARIES})
target_link_libraries(${exe} poppler-qt5 ${Qt5Widgets_LIBRARIES} ${Qt5Test_LIBRARIES})
if(MSVC)
target_link_libraries(${exe} poppler ${poppler_LIBS})
endif()
......@@ -54,6 +54,7 @@ qt5_add_simpletest(stress-poppler-dir-qt5 stress-poppler-dir.cpp)
qt5_add_simpletest(stress-threads-qt5 stress-threads-qt5.cpp)
qt5_add_simpletest(poppler-qt5-texts poppler-texts.cpp)
qt5_add_simpletest(poppler-qt5-page-labels poppler-page-labels.cpp)
qt5_add_simpletest(bench-qt5-render bench-render.cpp)
qt5_add_qtest(check_qt5_attachments check_attachments.cpp)
qt5_add_qtest(check_qt5_dateConversion check_dateConversion.cpp)
......
#include <cstdlib>
#include <cstring>
#include <memory>
#include <QtTest/QtTest>
#include "PDFDoc.h"
#include "TextOutputDev.h"
#include "PSOutputDev.h"
namespace
{
std::unique_ptr<PDFDoc> openDocument(const char *filePath) {
std::unique_ptr<PDFDoc> document{
new PDFDoc(new GooString(filePath), nullptr, nullptr, nullptr)
};
if (!document->isOk()) {
document.reset();
}
return document;
}
std::unique_ptr<TextOutputDev> openTextDevice() {
std::unique_ptr<TextOutputDev> device{
new TextOutputDev(nullptr, false, 0.0, false, false)
};
if (!device->isOk()) {
device.reset();
}
return device;
}
void displayPageAsText(PDFDoc *document, TextOutputDev *device, int page) {
document->displayPage(
device, page,
72.0, 72.0, 0,
false, false, false
);
delete device->makeWordList();
}
void dummyOutputFunction(void*, const char*, int) {}
std::unique_ptr<PSOutputDev> openPostScriptDevice(PDFDoc *document, const std::vector<int>& pages) {
std::unique_ptr<PSOutputDev> device{
new PSOutputDev(dummyOutputFunction, nullptr, nullptr, document, pages, psModePS)
};
if (!device->isOk()) {
device.reset();
}
return device;
}
void displayPageAsPostScript(PDFDoc *document, PSOutputDev *device, int page) {
document->displayPage(
device, page,
72.0, 72.0, 0,
false, false, false
);
}
}
class BenchRender : public QObject
{
Q_OBJECT
private:
void addPathsFromEnv(const char* env_var);
private slots:
void initTestCase();
void cleanupTestCase();
void benchText_data();
void benchText();
void benchPostScript_data();
void benchPostScript();
};
void BenchRender::addPathsFromEnv(const char* env_var)
{
char* var = std::getenv(env_var);
if (var == nullptr) {
return;
}
QTest::addColumn<QByteArray>("filePath");
for (char *path = std::strtok(var, "\n"); path != nullptr; path = std::strtok(nullptr, "\n")) {
QTest::addRow("%s", path) << QByteArray(path);
}
}
void BenchRender::initTestCase()
{
globalParams = new GlobalParams();
}
void BenchRender::cleanupTestCase()
{
delete globalParams;
globalParams = nullptr;
}
void BenchRender::benchText_data()
{
addPathsFromEnv("BENCH_RENDER_TEXT");
}
void BenchRender::benchText()
{
QFETCH(QByteArray, filePath);
auto document = openDocument(filePath.constData());
QVERIFY(document);
const auto device = openTextDevice();
QVERIFY(device);
QBENCHMARK {
for (int page = 1, pageCount = document->getNumPages(); page <= pageCount; ++page) {
displayPageAsText(document.get(), device.get(), page);
}
}
}
void BenchRender::benchPostScript_data()
{
addPathsFromEnv("BENCH_RENDER_POSTSCRIPT");
}
void BenchRender::benchPostScript()
{
QFETCH(QByteArray, filePath);
auto document = openDocument(filePath.constData());
QVERIFY(document);
std::vector<int> pages(document->getNumPages());
std::iota(pages.begin(), pages.end(), 1);
const auto device = openPostScriptDevice(document.get(), pages);
QVERIFY(device);
QBENCHMARK {
for (int page : pages) {
displayPageAsPostScript(document.get(), device.get(), page);
}
}
}
QTEST_GUILESS_MAIN(BenchRender)
#include "bench-render.moc"
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment