Krita is a free and open source cross-platform application that offers an end-to-end solution for creating digital art files from scratch built on the KDE and Qt frameworks.
C++
/*
* SPDX-FileCopyrightText: 2017 Dmitry Kazakov <[email protected]>
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "FreehandStrokeBenchmark.h"
#include "KisAsynchronousStrokeUpdateHelper.h"
#include "kis_image.h"
#include "kis_resources_snapshot.h"
#include "stroke_testing_utils.h"
#include "strokes/KisFreehandStrokeInfo.h"
#include "strokes/freehand_stroke.h"
#include <KoColor.h>
#include <KoCompositeOpRegistry.h>
#include <brushengine/kis_paint_information.h>
#include <simpletest.h>
#include <testui.h>
#include <QThread>
#include "testutil.h"
#include "KisResourceModel.h"
#include "KisGlobalResourcesInterface.h"
#include <memory>
class FreehandStrokeBenchmarkTester : public utils::StrokeTester
{
public:
FreehandStrokeBenchmarkTester(const QString &presetFilename)
: StrokeTester("freehand_benchmark", QSize(5000, 5000), presetFilename)
{
setBaseFuzziness(3);
}
void setCpuCoresLimit(int value) {
m_cpuCoresLimit = value;
}
protected:
using utils::StrokeTester::initImage;
void initImage(KisImageWSP image, KisNodeSP activeNode) override {
Q_UNUSED(activeNode);
if (m_cpuCoresLimit > 0) {
image->setWorkingThreadsLimit(m_cpuCoresLimit);
}
}
KisStrokeStrategy* createStroke(KisResourcesSnapshotSP resources,
KisImageWSP image) override {
Q_UNUSED(image);
KisFreehandStrokeInfo *strokeInfo = new KisFreehandStrokeInfo();
std::unique_ptr<FreehandStrokeStrategy> stroke(
new FreehandStrokeStrategy(resources, strokeInfo, kundo2_noi18n("Freehand Stroke")));
return stroke.release();
}
void addPaintingJobs(KisImageWSP image,
KisResourcesSnapshotSP resources) override
{
addPaintingJobs(image, resources, 0);
}
void addPaintingJobs(KisImageWSP image, KisResourcesSnapshotSP resources, int iteration) override {
Q_UNUSED(iteration);
Q_UNUSED(resources);
for (int y = 100; y < 4900; y += 300) {
KisPaintInformation pi1;
KisPaintInformation pi2;
pi1 = KisPaintInformation(QPointF(100, y), 0.5);
pi2 = KisPaintInformation(QPointF(4900, y + 100), 1.0);
std::unique_ptr<KisStrokeJobData> data(
new FreehandStrokeStrategy::Data(0, pi1, pi2));
image->addJob(strokeId(), data.release());
}
image->addJob(strokeId(), new KisAsynchronousStrokeUpdateHelper::UpdateData(true));
}
private:
int m_cpuCoresLimit = -1;
};
void benchmarkBrush(const QString &presetName)
{
FreehandStrokeBenchmarkTester tester(presetName);
for (int i = 1; i <= QThread::idealThreadCount(); i++) {
tester.setCpuCoresLimit(i);
tester.benchmark();
qDebug() << qPrintable(QString("Cores: %1 Time: %2 (ms)").arg(i).arg(tester.lastStrokeTime()));
}
}
void benchmarkBrushUnthreaded(const QString &presetName)
{
FreehandStrokeBenchmarkTester tester(presetName);
Q_FOREACH(int i, QVector<int>({1, QThread::idealThreadCount()})) {
tester.setCpuCoresLimit(i);
tester.benchmark();
qDebug() << qPrintable(QString("Cores: %1 Time: %2 (ms)").arg(i).arg(tester.lastStrokeTime()));
}
}
#include <KoResourcePaths.h>
#include <KisSupportedArchitectures.h>
void FreehandStrokeBenchmark::initTestCase()
{
{
QString fullFileName = TestUtil::fetchDataFileLazy("3_texture.png");
KIS_ASSERT(!fullFileName.isEmpty());
KIS_ASSERT(QFileInfo(fullFileName).exists());
KisResourceModel model(ResourceType::Brushes);
model.importResourceFile(fullFileName, true);
}
{
QString fullFileName = TestUtil::fetchDataFileLazy("DA_RGBA bluegreen_small1.png");
KIS_ASSERT(!fullFileName.isEmpty());
KIS_ASSERT(QFileInfo(fullFileName).exists());
KisResourceModel model(ResourceType::Brushes);
model.importResourceFile(fullFileName, true);
}
// warm-up memory pools
{
FreehandStrokeBenchmarkTester tester("testing_1000px_auto_default.kpp");
tester.setCpuCoresLimit(QThread::idealThreadCount());
tester.benchmark();
QTest::qSleep(500);
}
qDebug() << "Base instruction set:" << KisSupportedArchitectures::baseArchName();
qDebug() << "Optimized code uses set:" << KisSupportedArchitectures::bestArchName();
qDebug() << "Supported instruction sets:" << KisSupportedArchitectures::supportedInstructionSets();
}
void FreehandStrokeBenchmark::testDefaultTip()
{
benchmarkBrush("testing_1000px_auto_default.kpp");
}
void FreehandStrokeBenchmark::testSoftTip()
{
benchmarkBrushUnthreaded("testing_1000px_auto_soft.kpp");
}
void FreehandStrokeBenchmark::testGaussianTip()
{
benchmarkBrushUnthreaded("testing_1000px_auto_gaussian.kpp");
}
void FreehandStrokeBenchmark::testRectangularTip()
{
benchmarkBrushUnthreaded("testing_1000px_auto_rectangular.kpp");
}
void FreehandStrokeBenchmark::testRectGaussianTip()
{
benchmarkBrushUnthreaded("testing_1000px_auto_gaussian_rect.kpp");
}
void FreehandStrokeBenchmark::testRectSoftTip()
{
benchmarkBrushUnthreaded("testing_1000px_auto_soft_rect.kpp");
}
void FreehandStrokeBenchmark::testStampTip()
{
benchmarkBrushUnthreaded("testing_1000px_stamp_450_rotated.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeDefaultTip_dull_old_sa()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_default_dulling_old_sa.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeDefaultTip_dull_old_nsa()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_default_dulling_old_nsa.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeDefaultTip_dull_new_sa()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_default_dulling_new_sa.kpp");
}
#ifndef LIMIT_LONG_TESTS
void FreehandStrokeBenchmark::testColorsmudgeDefaultTip_dull_new_sa_800px()
{
benchmarkBrushUnthreaded("testing_800px_colorsmudge_default_dulling_new_sa.kpp");
}
#endif
void FreehandStrokeBenchmark::testColorsmudgeDefaultTip_dull_new_nsa()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_default_dulling_new_nsa.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeDefaultTip_smear_old_sa()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_default_smearing_old_sa.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeDefaultTip_smear_old_nsa()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_default_smearing_old_nsa.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeDefaultTip_smear_new_sa()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_default_smearing_new_sa.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeDefaultTip_smear_new_nsa()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_default_smearing_new_nsa.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeLightness_smear_new_nsa_maskmode()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_lightness_smearing_new_nsa_maskmode.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeLightness_smear_new_nsa_nopt()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_lightness_smearing_new_nsa_nopt.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeLightness_smear_new_nsa_ptoverlay()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_lightness_smearing_new_nsa_ptoverlay.kpp");
}
void FreehandStrokeBenchmark::testColorsmudgeLightness_smear_new_nsa_ptoverwrite()
{
benchmarkBrushUnthreaded("testing_200px_colorsmudge_lightness_smearing_new_nsa_ptoverwrite.kpp");
}
KISTEST_MAIN(FreehandStrokeBenchmark)