Commit 17e2d401 authored by Boudewijn Rempt's avatar Boudewijn Rempt

Move the benchmarks from KisPainterTest to KisPainterBenchmark

parent 1f1215e4
......@@ -47,6 +47,11 @@ inline double drand48()
#include <kis_image.h>
#include <kis_painter.h>
#include <kis_types.h>
#include "kis_paintop_utils.h"
#include "kis_algebra_2d.h"
#include "kis_paint_device_debug_utils.h"
#include "KisRenderedDab.h"
#define SAVE_OUTPUT
......@@ -275,4 +280,186 @@ void KisPainterBenchmark::benchmarkDrawScanLine()
#endif
}
void KisPainterBenchmark::benchmarkBitBlt2()
{
quint8 p = 128;
const KoColorSpace *cs = KoColorSpaceRegistry::instance()->alpha8();
KisPaintDeviceSP src = new KisPaintDevice(cs);
KisPaintDeviceSP dst = new KisPaintDevice(cs);
KoColor color(&p, cs);
QRect fillRect(0,0,5000,5000);
src->fill(fillRect, color);
QBENCHMARK {
KisPainter gc(dst);
gc.bitBlt(QPoint(), src, fillRect);
}
}
void KisPainterBenchmark::benchmarkBitBltOldData()
{
quint8 p = 128;
const KoColorSpace *cs = KoColorSpaceRegistry::instance()->alpha8();
KisPaintDeviceSP src = new KisPaintDevice(cs);
KisPaintDeviceSP dst = new KisPaintDevice(cs);
KoColor color(&p, cs);
QRect fillRect(0,0,5000,5000);
src->fill(fillRect, color);
QBENCHMARK {
KisPainter gc(dst);
gc.bitBltOldData(QPoint(), src, fillRect);
}
}
void benchmarkMassiveBltFixedImpl(int numDabs, int size, qreal spacing, int idealNumPatches, Qt::Orientations direction)
{
const KoColorSpace* cs = KoColorSpaceRegistry::instance()->rgb8();
KisPaintDeviceSP dst = new KisPaintDevice(cs);
QList<QColor> colors;
colors << QColor(255, 0, 0, 200);
colors << QColor(0, 255, 0, 200);
colors << QColor(0, 0, 255, 200);
QRect devicesRect;
QList<KisRenderedDab> devices;
const int step = spacing * size;
for (int i = 0; i < numDabs; i++) {
const QRect rc =
direction == Qt::Horizontal ? QRect(10 + i * step, 0, size, size) :
direction == Qt::Vertical ? QRect(0, 10 + i * step, size, size) :
QRect(10 + i * step, 10 + i * step, size, size);
KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs);
dev->setRect(rc);
dev->initialize();
dev->fill(rc, KoColor(colors[i % 3], cs));
dev->fill(kisGrowRect(rc, -5), KoColor(Qt::white, cs));
KisRenderedDab dab;
dab.device = dev;
dab.offset = dev->bounds().topLeft();
dab.opacity = 1.0;
dab.flow = 1.0;
devices << dab;
devicesRect |= rc;
}
const QRect fullRect = kisGrowRect(devicesRect, 10);
{
KisPainter painter(dst);
painter.bltFixed(fullRect, devices);
painter.end();
//QVERIFY(TestUtil::checkQImage(dst->convertToQImage(0, fullRect),
// "kispainter_test",
// "massive_bitblt_benchmark",
// "initial"));
dst->clear();
}
QVector<QRect> dabRects;
Q_FOREACH (const KisRenderedDab &dab, devices) {
dabRects.append(dab.realBounds());
}
QElapsedTimer t;
qint64 massiveTime = 0;
int massiveTries = 0;
int numRects = 0;
int avgPatchSize = 0;
for (int i = 0; i < 50 || massiveTime > 5000000; i++) {
QVector<QRect> rects = KisPaintOpUtils::splitDabsIntoRects(dabRects, idealNumPatches, size, spacing);
numRects = rects.size();
// HACK: please calculate real *average*!
avgPatchSize = KisAlgebra2D::maxDimension(rects.first());
t.start();
KisPainter painter(dst);
Q_FOREACH (const QRect &rc, rects) {
painter.bltFixed(rc, devices);
}
painter.end();
massiveTime += t.nsecsElapsed() / 1000;
massiveTries++;
dst->clear();
}
qint64 linearTime = 0;
int linearTries = 0;
for (int i = 0; i < 50 || linearTime > 5000000; i++) {
t.start();
KisPainter painter(dst);
Q_FOREACH (const KisRenderedDab &dab, devices) {
painter.setOpacity(255 * dab.opacity);
painter.setFlow(255 * dab.flow);
painter.bltFixed(dab.offset, dab.device, dab.device->bounds());
}
painter.end();
linearTime += t.nsecsElapsed() / 1000;
linearTries++;
dst->clear();
}
const qreal avgMassive = qreal(massiveTime) / massiveTries;
const qreal avgLinear = qreal(linearTime) / linearTries;
const QString directionMark =
direction == Qt::Horizontal ? "H" :
direction == Qt::Vertical ? "V" : "D";
qDebug()
<< "D:" << size
<< "S:" << spacing
<< "N:" << numDabs
<< "P (px):" << avgPatchSize
<< "R:" << numRects
<< "Dir:" << directionMark
<< "\t"
<< qPrintable(QString("Massive (usec): %1").arg(QString::number(avgMassive, 'f', 2), 8))
<< "\t"
<< qPrintable(QString("Linear (usec): %1").arg(QString::number(avgLinear, 'f', 2), 8))
<< (avgMassive < avgLinear ? "*" : " ")
<< qPrintable(QString("%1")
.arg(QString::number((avgMassive - avgLinear) / avgLinear * 100.0, 'f', 2), 8))
<< qRound(size + size * spacing * (numDabs - 1));
}
void KisPainterBenchmark::benchmarkMassiveBltFixed()
{
const qreal sp = 0.14;
const int idealThreadCount = 8;
for (int d = 50; d < 301; d += 50) {
for (int n = 1; n < 150; n = qCeil(n * 1.5)) {
benchmarkMassiveBltFixedImpl(n, d, sp, idealThreadCount, Qt::Horizontal);
benchmarkMassiveBltFixedImpl(n, d, sp, idealThreadCount, Qt::Vertical);
benchmarkMassiveBltFixedImpl(n, d, sp, idealThreadCount, Qt::Vertical | Qt::Horizontal);
}
}
}
QTEST_MAIN(KisPainterBenchmark)
......@@ -48,6 +48,11 @@ private Q_SLOTS:
void benchmarkDrawThickLine();
void benchmarkDrawQtLine();
void benchmarkDrawScanLine();
void benchmarkBitBlt2();
void benchmarkBitBltOldData();
void benchmarkMassiveBltFixed();
};
......
......@@ -481,43 +481,6 @@ void KisPainterTest::testBitBltOldData()
srcGc.deleteTransaction();
}
void KisPainterTest::benchmarkBitBlt()
{
quint8 p = 128;
const KoColorSpace *cs = KoColorSpaceRegistry::instance()->alpha8();
KisPaintDeviceSP src = new KisPaintDevice(cs);
KisPaintDeviceSP dst = new KisPaintDevice(cs);
KoColor color(&p, cs);
QRect fillRect(0,0,5000,5000);
src->fill(fillRect, color);
QBENCHMARK {
KisPainter gc(dst);
gc.bitBlt(QPoint(), src, fillRect);
}
}
void KisPainterTest::benchmarkBitBltOldData()
{
quint8 p = 128;
const KoColorSpace *cs = KoColorSpaceRegistry::instance()->alpha8();
KisPaintDeviceSP src = new KisPaintDevice(cs);
KisPaintDeviceSP dst = new KisPaintDevice(cs);
KoColor color(&p, cs);
QRect fillRect(0,0,5000,5000);
src->fill(fillRect, color);
QBENCHMARK {
KisPainter gc(dst);
gc.bitBltOldData(QPoint(), src, fillRect);
}
}
#include "kis_paint_device_debug_utils.h"
#include "KisRenderedDab.h"
......@@ -659,150 +622,6 @@ void KisPainterTest::testMassiveBltFixedCornerCases()
}
#include "kis_paintop_utils.h"
#include "kis_algebra_2d.h"
void benchmarkMassiveBltFixedImpl(int numDabs, int size, qreal spacing, int idealNumPatches, Qt::Orientations direction)
{
const KoColorSpace* cs = KoColorSpaceRegistry::instance()->rgb8();
KisPaintDeviceSP dst = new KisPaintDevice(cs);
QList<QColor> colors;
colors << QColor(255, 0, 0, 200);
colors << QColor(0, 255, 0, 200);
colors << QColor(0, 0, 255, 200);
QRect devicesRect;
QList<KisRenderedDab> devices;
const int step = spacing * size;
for (int i = 0; i < numDabs; i++) {
const QRect rc =
direction == Qt::Horizontal ? QRect(10 + i * step, 0, size, size) :
direction == Qt::Vertical ? QRect(0, 10 + i * step, size, size) :
QRect(10 + i * step, 10 + i * step, size, size);
KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs);
dev->setRect(rc);
dev->initialize();
dev->fill(rc, KoColor(colors[i % 3], cs));
dev->fill(kisGrowRect(rc, -5), KoColor(Qt::white, cs));
KisRenderedDab dab;
dab.device = dev;
dab.offset = dev->bounds().topLeft();
dab.opacity = 1.0;
dab.flow = 1.0;
devices << dab;
devicesRect |= rc;
}
const QRect fullRect = kisGrowRect(devicesRect, 10);
{
KisPainter painter(dst);
painter.bltFixed(fullRect, devices);
painter.end();
//QVERIFY(TestUtil::checkQImage(dst->convertToQImage(0, fullRect),
// "kispainter_test",
// "massive_bitblt_benchmark",
// "initial"));
dst->clear();
}
QVector<QRect> dabRects;
Q_FOREACH (const KisRenderedDab &dab, devices) {
dabRects.append(dab.realBounds());
}
QElapsedTimer t;
qint64 massiveTime = 0;
int massiveTries = 0;
int numRects = 0;
int avgPatchSize = 0;
for (int i = 0; i < 50 || massiveTime > 5000000; i++) {
QVector<QRect> rects = KisPaintOpUtils::splitDabsIntoRects(dabRects, idealNumPatches, size, spacing);
numRects = rects.size();
// HACK: please calculate real *average*!
avgPatchSize = KisAlgebra2D::maxDimension(rects.first());
t.start();
KisPainter painter(dst);
Q_FOREACH (const QRect &rc, rects) {
painter.bltFixed(rc, devices);
}
painter.end();
massiveTime += t.nsecsElapsed() / 1000;
massiveTries++;
dst->clear();
}
qint64 linearTime = 0;
int linearTries = 0;
for (int i = 0; i < 50 || linearTime > 5000000; i++) {
t.start();
KisPainter painter(dst);
Q_FOREACH (const KisRenderedDab &dab, devices) {
painter.setOpacity(255 * dab.opacity);
painter.setFlow(255 * dab.flow);
painter.bltFixed(dab.offset, dab.device, dab.device->bounds());
}
painter.end();
linearTime += t.nsecsElapsed() / 1000;
linearTries++;
dst->clear();
}
const qreal avgMassive = qreal(massiveTime) / massiveTries;
const qreal avgLinear = qreal(linearTime) / linearTries;
const QString directionMark =
direction == Qt::Horizontal ? "H" :
direction == Qt::Vertical ? "V" : "D";
qDebug()
<< "D:" << size
<< "S:" << spacing
<< "N:" << numDabs
<< "P (px):" << avgPatchSize
<< "R:" << numRects
<< "Dir:" << directionMark
<< "\t"
<< qPrintable(QString("Massive (usec): %1").arg(QString::number(avgMassive, 'f', 2), 8))
<< "\t"
<< qPrintable(QString("Linear (usec): %1").arg(QString::number(avgLinear, 'f', 2), 8))
<< (avgMassive < avgLinear ? "*" : " ")
<< qPrintable(QString("%1")
.arg(QString::number((avgMassive - avgLinear) / avgLinear * 100.0, 'f', 2), 8))
<< qRound(size + size * spacing * (numDabs - 1));
}
void KisPainterTest::benchmarkMassiveBltFixed()
{
const qreal sp = 0.14;
const int idealThreadCount = 8;
for (int d = 50; d < 301; d += 50) {
for (int n = 1; n < 150; n = qCeil(n * 1.5)) {
benchmarkMassiveBltFixedImpl(n, d, sp, idealThreadCount, Qt::Horizontal);
benchmarkMassiveBltFixedImpl(n, d, sp, idealThreadCount, Qt::Vertical);
benchmarkMassiveBltFixedImpl(n, d, sp, idealThreadCount, Qt::Vertical | Qt::Horizontal);
}
}
}
#include "kis_lod_transform.h"
inline QRect extentifyRect(const QRect &rc)
......
......@@ -51,8 +51,6 @@ private Q_SLOTS:
void testSelectionBitBltEraseCompositeOp();
void testBitBltOldData();
void benchmarkBitBlt();
void benchmarkBitBltOldData();
void testMassiveBltFixedSingleTile();
void testMassiveBltFixedMultiTile();
......@@ -63,7 +61,6 @@ private Q_SLOTS:
void testMassiveBltFixedCornerCases();
void benchmarkMassiveBltFixed();
void testOptimizedCopying();
};
......
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