From: Christian Pulvermacher Date: Tue, 26 Oct 2010 22:49:25 +0000 (+0200) Subject: add painting benchmark X-Git-Tag: 0.7~11 X-Git-Url: https://vcs.maemo.org/git/?p=presencevnc;a=commitdiff_plain;h=8b08a50436ddbd2674b578718901e37e4332bdd9 add painting benchmark --- diff --git a/test/painting.cpp b/test/painting.cpp new file mode 100644 index 0000000..9214c0d --- /dev/null +++ b/test/painting.cpp @@ -0,0 +1,132 @@ +#include +#include + +//use this rectangle in source image +const int src_xoff = 15; +const int src_yoff = 23; +const int src_width = 600; +const int src_height = 500; +const QRect src_rect(src_xoff, src_yoff, src_width, src_height); + + +class Widget : public QWidget { +public: + Widget(): + QWidget(0) + { + msecs = paints = mode = 0; + img = QImage("test.png"); + + QTimer *timer = new QTimer(this); + connect(timer, SIGNAL(timeout()), + this, SLOT(repaint())); + timer->start(150); + + } +protected: + virtual void paintEvent(QPaintEvent*); +private: + QImage img; + int msecs, paints, mode; +}; + +void Widget::paintEvent(QPaintEvent*) +{ + QPainter painter(this); + + QTime t; + t.start(); + + switch(mode) { +//scaled (fit to window) + case 0: //this is how small updates in 0.6 are done + painter.drawImage(rect(), + img.copy(src_rect) + .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + break; + case 1: //fast transformation + painter.drawImage(rect(), + img.copy(src_rect) + .scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation)); + break; + case 2: //tell drawImage() that no further scaling is required + //why different from 1? + painter.drawImage(rect().topLeft(), + img.copy(src_rect) + .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + break; + case 3: //avoid scaled() + painter.drawImage(rect(), + img.copy(src_rect)); + break; + case 4: //avoid copy() and scaled() + painter.drawImage(rect(), img, src_rect); + break; + +// not scaled - repeat preceeding tests with dimensions that just happen to require no transformation +// these are all comparable + case 5: //this is how small updates in 0.6 are done + painter.drawImage(rect(), + img.copy(rect()) + .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + break; + case 6: //fast transformation + painter.drawImage(rect(), + img.copy(rect()) + .scaled(size(), Qt::IgnoreAspectRatio, Qt::FastTransformation)); + break; + case 7: //tell drawImage() that no further scaling is required + painter.drawImage(rect().topLeft(), + img.copy(rect()) + .scaled(size(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation)); + break; + case 8: //avoid scaled() + painter.drawImage(rect(), + img.copy(rect())); + break; + case 9: //avoid copy() and scaled() + painter.drawImage(rect(), img, rect()); + break; +//and a few extra + case 10: + painter.drawImage(rect().topLeft(), img, rect()); + break; + case 11: + painter.drawImage(rect().topLeft(), img); + break; + case 12: + painter.drawImage(rect().topLeft(), + img.copy(rect())); + break; + case 13: //5 with KeepAspectRatio + painter.drawImage(rect(), + img.copy(rect()) + .scaled(size(), Qt::KeepAspectRatio, Qt::SmoothTransformation)); + break; + } + + msecs += t.elapsed(); + paints++; + + const int paints_per_mode = 20; + const int num_modes = 14; + + if(paints > paints_per_mode) { + std::cout << mode << ":\t" << double(msecs)/paints << " msecs per paint\n"; + msecs = paints = 0; + mode++; + if(mode >= num_modes) + close(); + } + +} + +int main(int argc, char* argv[]) +{ + QApplication app(argc, argv); + + Widget w; + w.show(); + + return app.exec(); +} diff --git a/test/test.png b/test/test.png new file mode 100644 index 0000000..fce6c7a Binary files /dev/null and b/test/test.png differ diff --git a/test/test.pro b/test/test.pro new file mode 100644 index 0000000..c8b1017 --- /dev/null +++ b/test/test.pro @@ -0,0 +1,11 @@ +###################################################################### +# Automatically generated by qmake (2.01a) Sun Oct 24 20:20:52 2010 +###################################################################### + +TEMPLATE = app +TARGET = +DEPENDPATH += . +INCLUDEPATH += . + +# Input +SOURCES += painting.cpp diff --git a/test/testresults b/test/testresults new file mode 100644 index 0000000..b2fff31 --- /dev/null +++ b/test/testresults @@ -0,0 +1,16 @@ +eee-PC, fbdev, fullscreen, Qt 4.4.3 + +0: 69.0952 msecs per paint +1: 42.7143 msecs per paint +2: 70.4762 msecs per paint +3: 61.619 msecs per paint +4: 108.619 msecs per paint +5: 28.381 msecs per paint +6: 28.4762 msecs per paint +7: 28.1429 msecs per paint +8: 23 msecs per paint +9: 38.3333 msecs per paint +10: 38.2857 msecs per paint +11: 54.8571 msecs per paint +12: 23.0476 msecs per paint +13: 29.2381 msecs per paint