summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/gui/kernel
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/gui/kernel')
-rw-r--r--tests/benchmarks/gui/kernel/kernel.pro4
-rw-r--r--tests/benchmarks/gui/kernel/qapplication/main.cpp71
-rw-r--r--tests/benchmarks/gui/kernel/qapplication/qapplication.pro10
-rw-r--r--tests/benchmarks/gui/kernel/qguimetatype/qguimetatype.pro6
-rw-r--r--tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp113
-rw-r--r--tests/benchmarks/gui/kernel/qguivariant/qguivariant.pro6
-rw-r--r--tests/benchmarks/gui/kernel/qguivariant/tst_qguivariant.cpp111
-rw-r--r--tests/benchmarks/gui/kernel/qwidget/qwidget.pro4
-rw-r--r--tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp260
9 files changed, 585 insertions, 0 deletions
diff --git a/tests/benchmarks/gui/kernel/kernel.pro b/tests/benchmarks/gui/kernel/kernel.pro
new file mode 100644
index 0000000000..a50aad2014
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/kernel.pro
@@ -0,0 +1,4 @@
+TEMPLATE = subdirs
+SUBDIRS = \
+ qapplication \
+ qwidget
diff --git a/tests/benchmarks/gui/kernel/qapplication/main.cpp b/tests/benchmarks/gui/kernel/qapplication/main.cpp
new file mode 100644
index 0000000000..9647f6e642
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qapplication/main.cpp
@@ -0,0 +1,71 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+#include <QApplication>
+
+#include <qtest.h>
+
+
+class tst_qapplication : public QObject
+{
+ Q_OBJECT
+private slots:
+ void ctor();
+};
+
+/*
+ Test the performance of the QApplication constructor.
+
+ Note: results from the second start on can be misleading,
+ since all global statics are already initialized.
+*/
+void tst_qapplication::ctor()
+{
+ // simulate reasonable argc, argv
+ int argc = 1;
+ char *argv[] = { "tst_qapplication" };
+ QBENCHMARK {
+ QApplication app(argc, argv);
+ }
+}
+
+QTEST_APPLESS_MAIN(tst_qapplication)
+
+#include "main.moc"
diff --git a/tests/benchmarks/gui/kernel/qapplication/qapplication.pro b/tests/benchmarks/gui/kernel/qapplication/qapplication.pro
new file mode 100644
index 0000000000..e12a60c54c
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qapplication/qapplication.pro
@@ -0,0 +1,10 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_bench_qapplication
+DEPENDPATH += .
+INCLUDEPATH += .
+
+CONFIG += release
+
+# Input
+SOURCES += main.cpp
diff --git a/tests/benchmarks/gui/kernel/qguimetatype/qguimetatype.pro b/tests/benchmarks/gui/kernel/qguimetatype/qguimetatype.pro
new file mode 100644
index 0000000000..7ef99e4cb4
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qguimetatype/qguimetatype.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_bench_qguimetatype
+
+SOURCES += tst_qguimetatype.cpp
+
diff --git a/tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp b/tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp
new file mode 100644
index 0000000000..fd5132c02f
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qguimetatype/tst_qguimetatype.cpp
@@ -0,0 +1,113 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QtCore/qmetatype.h>
+
+class tst_QGuiMetaType : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QGuiMetaType();
+ virtual ~tst_QGuiMetaType();
+
+private slots:
+ void constructGuiType_data();
+ void constructGuiType();
+ void constructGuiTypeCopy_data();
+ void constructGuiTypeCopy();
+};
+
+tst_QGuiMetaType::tst_QGuiMetaType()
+{
+}
+
+tst_QGuiMetaType::~tst_QGuiMetaType()
+{
+}
+
+void tst_QGuiMetaType::constructGuiType_data()
+{
+ QTest::addColumn<int>("typeId");
+ for (int i = QMetaType::FirstGuiType; i <= QMetaType::LastGuiType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+}
+
+// Tests how fast QMetaType can default-construct and destroy a Qt GUI
+// type. The purpose of this benchmark is to measure the overhead of
+// using type id-based creation compared to creating the type directly
+// (i.e. "T *t = new T(); delete t;").
+void tst_QGuiMetaType::constructGuiType()
+{
+ QFETCH(int, typeId);
+ QBENCHMARK {
+ for (int i = 0; i < 100000; ++i) {
+ void *data = QMetaType::construct(typeId, (void *)0);
+ QMetaType::destroy(typeId, data);
+ }
+ }
+}
+
+void tst_QGuiMetaType::constructGuiTypeCopy_data()
+{
+ constructGuiType_data();
+}
+
+// Tests how fast QMetaType can copy-construct and destroy a Qt GUI
+// type. The purpose of this benchmark is to measure the overhead of
+// using type id-based creation compared to creating the type directly
+// (i.e. "T *t = new T(other); delete t;").
+void tst_QGuiMetaType::constructGuiTypeCopy()
+{
+ QFETCH(int, typeId);
+ QVariant other(typeId, (void *)0);
+ const void *copy = other.constData();
+ QBENCHMARK {
+ for (int i = 0; i < 100000; ++i) {
+ void *data = QMetaType::construct(typeId, copy);
+ QMetaType::destroy(typeId, data);
+ }
+ }
+}
+
+QTEST_MAIN(tst_QGuiMetaType)
+#include "tst_qguimetatype.moc"
diff --git a/tests/benchmarks/gui/kernel/qguivariant/qguivariant.pro b/tests/benchmarks/gui/kernel/qguivariant/qguivariant.pro
new file mode 100644
index 0000000000..4e05dd7d4b
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qguivariant/qguivariant.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_bench_qguivariant
+
+SOURCES += tst_qguivariant.cpp
+
diff --git a/tests/benchmarks/gui/kernel/qguivariant/tst_qguivariant.cpp b/tests/benchmarks/gui/kernel/qguivariant/tst_qguivariant.cpp
new file mode 100644
index 0000000000..a9e49b5de2
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qguivariant/tst_qguivariant.cpp
@@ -0,0 +1,111 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QtCore/qvariant.h>
+
+#define ITERATION_COUNT 1e5
+
+class tst_QGuiVariant : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QGuiVariant();
+ virtual ~tst_QGuiVariant();
+
+private slots:
+ void createGuiType_data();
+ void createGuiType();
+ void createGuiTypeCopy_data();
+ void createGuiTypeCopy();
+};
+
+tst_QGuiVariant::tst_QGuiVariant()
+{
+}
+
+tst_QGuiVariant::~tst_QGuiVariant()
+{
+}
+
+void tst_QGuiVariant::createGuiType_data()
+{
+ QTest::addColumn<int>("typeId");
+ for (int i = QMetaType::FirstGuiType; i <= QMetaType::LastGuiType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+}
+
+// Tests how fast a Qt GUI type can be default-constructed by a
+// QVariant. The purpose of this benchmark is to measure the overhead
+// of creating (and destroying) a QVariant compared to creating the
+// type directly.
+void tst_QGuiVariant::createGuiType()
+{
+ QFETCH(int, typeId);
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ QVariant(typeId, (void *)0);
+ }
+}
+
+void tst_QGuiVariant::createGuiTypeCopy_data()
+{
+ createGuiType_data();
+}
+
+// Tests how fast a Qt GUI type can be copy-constructed by a
+// QVariant. The purpose of this benchmark is to measure the overhead
+// of creating (and destroying) a QVariant compared to creating the
+// type directly.
+void tst_QGuiVariant::createGuiTypeCopy()
+{
+ QFETCH(int, typeId);
+ QVariant other(typeId, (void *)0);
+ const void *copy = other.constData();
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ QVariant(typeId, copy);
+ }
+}
+
+QTEST_MAIN(tst_QGuiVariant)
+#include "tst_qguivariant.moc"
diff --git a/tests/benchmarks/gui/kernel/qwidget/qwidget.pro b/tests/benchmarks/gui/kernel/qwidget/qwidget.pro
new file mode 100644
index 0000000000..4c6e5c724d
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qwidget/qwidget.pro
@@ -0,0 +1,4 @@
+load(qttest_p4)
+
+TARGET = tst_bench_qwidget
+SOURCES += tst_qwidget.cpp
diff --git a/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp b/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp
new file mode 100644
index 0000000000..bcb1266490
--- /dev/null
+++ b/tests/benchmarks/gui/kernel/qwidget/tst_qwidget.cpp
@@ -0,0 +1,260 @@
+/****************************************************************************
+**
+** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QtGui>
+
+static void processEvents()
+{
+ QApplication::flush();
+ QApplication::processEvents();
+ QApplication::processEvents();
+}
+
+class UpdateWidget : public QWidget
+{
+public:
+ UpdateWidget(int rows, int columns)
+ : QWidget(0), rowCount(0), columnCount(0), opaqueChildren(false)
+ {
+ fill(rows, columns);
+ }
+
+ UpdateWidget(QWidget *parent = 0)
+ : QWidget(parent), rowCount(0), columnCount(0), opaqueChildren(false) {}
+
+ void fill(int rows, int columns)
+ {
+ if (rows == rowCount && columns == columnCount)
+ return;
+ delete layout();
+ QGridLayout *layout = new QGridLayout;
+ rowCount = rows;
+ columnCount = columns;
+ for (int row = 0; row < rowCount; ++row) {
+ for (int column = 0; column < columnCount; ++column) {
+ UpdateWidget *widget = new UpdateWidget;
+ widget->setFixedSize(20, 20);
+ layout->addWidget(widget, row, column);
+ children.append(widget);
+ }
+ }
+ setLayout(layout);
+ adjustSize();
+ QTest::qWait(250);
+ processEvents();
+ }
+
+ void setOpaqueChildren(bool enable)
+ {
+ if (opaqueChildren != enable) {
+ foreach (QWidget *w, children)
+ w->setAttribute(Qt::WA_OpaquePaintEvent, enable);
+ opaqueChildren = enable;
+ processEvents();
+ }
+ }
+
+ void paintEvent(QPaintEvent *)
+ {
+ static int color = Qt::black;
+
+ QPainter painter(this);
+ painter.fillRect(rect(), Qt::GlobalColor(color));
+
+ if (++color > Qt::darkYellow)
+ color = Qt::black;
+ }
+
+ QRegion updateRegion;
+ QList<UpdateWidget*> children;
+ int rowCount;
+ int columnCount;
+ bool opaqueChildren;
+};
+
+class tst_QWidget : public QObject
+{
+ Q_OBJECT
+
+public slots:
+ void initTestCase();
+ void init();
+
+private slots:
+ void update_data();
+ void update();
+ void updatePartial_data();
+ void updatePartial();
+ void updateComplex_data();
+ void updateComplex();
+
+private:
+ UpdateWidget widget;
+};
+
+void tst_QWidget::initTestCase()
+{
+ widget.show();
+ QTest::qWaitForWindowShown(&widget);
+ QTest::qWait(300);
+ processEvents();
+}
+
+void tst_QWidget::init()
+{
+ QVERIFY(widget.isVisible());
+ for (int i = 0; i < 3; ++i)
+ processEvents();
+}
+
+void tst_QWidget::update_data()
+{
+ QTest::addColumn<int>("rows");
+ QTest::addColumn<int>("columns");
+ QTest::addColumn<int>("numUpdates");
+ QTest::addColumn<bool>("opaque");
+
+ QTest::newRow("10x10x1 transparent") << 10 << 10 << 1 << false;
+ QTest::newRow("10x10x10 transparent") << 10 << 10 << 10 << false;
+ QTest::newRow("10x10x100 transparent") << 10 << 10 << 100 << false;
+ QTest::newRow("10x10x1 opaque") << 10 << 10 << 1 << true;
+ QTest::newRow("10x10x10 opaque") << 10 << 10 << 10 << true;
+ QTest::newRow("10x10x100 opaque") << 10 << 10 << 100 << true;
+#ifndef Q_OS_SYMBIAN
+ //These test cases cause stack overflow in QWidgetPrivate::paintSiblingsRecursive
+ //see http://bugreports.qt.nokia.com/browse/QTBUG-8512
+ //Symbian threads have a hard limit of 80kB user stack
+ QTest::newRow("25x25x1 transparent ") << 25 << 25 << 1 << false;
+ QTest::newRow("25x25x10 transparent") << 25 << 25 << 10 << false;
+ QTest::newRow("25x25x100 transparent") << 25 << 25 << 100 << false;
+ QTest::newRow("25x25x1 opaque") << 25 << 25 << 1 << true;
+ QTest::newRow("25x25x10 opaque") << 25 << 25 << 10 << true;
+ QTest::newRow("25x25x100 opaque") << 25 << 25 << 100 << true;
+#endif
+}
+
+void tst_QWidget::update()
+{
+ QFETCH(int, rows);
+ QFETCH(int, columns);
+ QFETCH(int, numUpdates);
+ QFETCH(bool, opaque);
+
+ widget.fill(rows, columns);
+ widget.setOpaqueChildren(opaque);
+
+ QBENCHMARK {
+ for (int i = 0; i < widget.children.size(); ++i) {
+ for (int j = 0; j < numUpdates; ++j)
+ widget.children.at(i)->update();
+ QApplication::processEvents();
+ }
+ }
+
+ QApplication::flush();
+}
+
+void tst_QWidget::updatePartial_data()
+{
+ update_data();
+}
+
+void tst_QWidget::updatePartial()
+{
+ QFETCH(int, rows);
+ QFETCH(int, columns);
+ QFETCH(int, numUpdates);
+ QFETCH(bool, opaque);
+
+ widget.fill(rows, columns);
+ widget.setOpaqueChildren(opaque);
+
+ QBENCHMARK {
+ for (int i = 0; i < widget.children.size(); ++i) {
+ QWidget *w = widget.children[i];
+ const int x = w->width() / 2;
+ const int y = w->height() / 2;
+ for (int j = 0; j < numUpdates; ++j) {
+ w->update(0, 0, x, y);
+ w->update(x, 0, x, y);
+ w->update(0, y, x, y);
+ w->update(x, y, x, y);
+ }
+ QApplication::processEvents();
+ }
+ }
+}
+
+void tst_QWidget::updateComplex_data()
+{
+ update_data();
+}
+
+void tst_QWidget::updateComplex()
+{
+ QFETCH(int, rows);
+ QFETCH(int, columns);
+ QFETCH(int, numUpdates);
+ QFETCH(bool, opaque);
+
+ widget.fill(rows, columns);
+ widget.setOpaqueChildren(opaque);
+
+ QBENCHMARK {
+ for (int i = 0; i < widget.children.size(); ++i) {
+ QWidget *w = widget.children[i];
+ const int x = w->width() / 2;
+ const int y = w->height() / 2;
+ QRegion r1(0, 0, x, y, QRegion::Ellipse);
+ QRegion r2(x, y, x, y, QRegion::Ellipse);
+ for (int j = 0; j < numUpdates; ++j) {
+ w->update(r1);
+ w->update(r2);
+ }
+ QApplication::processEvents();
+ }
+ }
+}
+
+QTEST_MAIN(tst_QWidget)
+
+#include "tst_qwidget.moc"