diff options
author | Thiago Macieira <thiago.macieira@nokia.com> | 2010-07-15 13:14:37 (GMT) |
---|---|---|
committer | Thiago Macieira <thiago.macieira@nokia.com> | 2010-07-15 13:14:37 (GMT) |
commit | 8106f716043c22d71ff3dcdf9cd8a4db258fa81f (patch) | |
tree | fef8ef2bcc78da549037c94451058fde10268edd /tests/benchmarks | |
parent | a98bda4b42b068c9c3220ae2aded41a263387ac2 (diff) | |
parent | 03c01176ebf423085e56ceabcf8335ca5027a786 (diff) | |
download | Qt-8106f716043c22d71ff3dcdf9cd8a4db258fa81f.zip Qt-8106f716043c22d71ff3dcdf9cd8a4db258fa81f.tar.gz Qt-8106f716043c22d71ff3dcdf9cd8a4db258fa81f.tar.bz2 |
Merge remote branch 'origin/4.7' into qt-master-from-4.7
Conflicts:
src/gui/kernel/qapplication.h
Diffstat (limited to 'tests/benchmarks')
-rw-r--r-- | tests/benchmarks/declarative/script/data/block.qml | 6 | ||||
-rw-r--r-- | tests/benchmarks/declarative/script/data/global.js | 54 | ||||
-rw-r--r-- | tests/benchmarks/declarative/script/data/global_prop.qml | 53 | ||||
-rw-r--r-- | tests/benchmarks/declarative/script/tst_script.cpp | 75 | ||||
-rw-r--r-- | tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp | 64 | ||||
-rw-r--r-- | tests/benchmarks/gui/text/qtext/main.cpp | 95 | ||||
-rw-r--r-- | tests/benchmarks/opengl/main.cpp | 51 |
7 files changed, 388 insertions, 10 deletions
diff --git a/tests/benchmarks/declarative/script/data/block.qml b/tests/benchmarks/declarative/script/data/block.qml index 4e5006e..f7b2ab3 100644 --- a/tests/benchmarks/declarative/script/data/block.qml +++ b/tests/benchmarks/declarative/script/data/block.qml @@ -47,7 +47,7 @@ Rectangle { function doSomethingDirect() { theObject.prop1 = 0; - for (var i = 0; i < 60; ++i) + for (var i = 0; i < 1000; ++i) theObject.prop1 += theObject.prop2; theObject.prop3 = theObject.prop1; @@ -57,7 +57,7 @@ Rectangle { theObject.prop1 = 0; var incrementObj = theObject; - for (var i = 0; i < 60; ++i) + for (var i = 0; i < 1000; ++i) incrementObj.prop1 += incrementObj.prop2; incrementObj.prop3 = incrementObj.prop1; @@ -67,7 +67,7 @@ Rectangle { theObject.prop1 = 0; var increment = theObject.prop2; - for (var i = 0; i < 60; ++i) + for (var i = 0; i < 1000; ++i) theObject.prop1 += increment; theObject.prop3 = theObject.prop1; diff --git a/tests/benchmarks/declarative/script/data/global.js b/tests/benchmarks/declarative/script/data/global.js new file mode 100644 index 0000000..5b86b4d --- /dev/null +++ b/tests/benchmarks/declarative/script/data/global.js @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +var incVar = 1; +var total; + +function doSomething() { + for (var i = 0; i < 10000; ++i) + Math.sin(90); +} + +function doIncrement() { + total = 0; + for (var i = 0; i < 100000; ++i) + total += incVar; +} diff --git a/tests/benchmarks/declarative/script/data/global_prop.qml b/tests/benchmarks/declarative/script/data/global_prop.qml new file mode 100644 index 0000000..4fb7ee7 --- /dev/null +++ b/tests/benchmarks/declarative/script/data/global_prop.qml @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2010 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$ +** +****************************************************************************/ + +import Qt 4.7 +import "global.js" as Program + +Rectangle { + width: 200; height: 200 + + signal triggered + signal incrementTriggered + + onTriggered: Program.doSomething(); + onIncrementTriggered: Program.doIncrement(); +} diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp index 99f294c..5a7e151 100644 --- a/tests/benchmarks/declarative/script/tst_script.cpp +++ b/tests/benchmarks/declarative/script/tst_script.cpp @@ -92,7 +92,12 @@ private slots: void block_data(); void block(); -private: + + void global_property_js(); + void global_property_qml(); + void global_property_qml_js(); + + void scriptfile_property(); }; inline QUrl TEST_FILE(const QString &filename) @@ -625,6 +630,74 @@ void tst_script::block() delete rect; } +#define GLOBALPROPERTY_PROGRAM \ + "(function() { " \ + " for (var ii = 0; ii < 10000; ++ii) { " \ + " Math.sin(90); " \ + " } " \ + "})" + +void tst_script::global_property_js() +{ + QScriptEngine engine; + + QScriptValue prog = engine.evaluate(GLOBALPROPERTY_PROGRAM); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::global_property_qml() +{ + QDeclarativeEngine qmlengine; + + QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(&qmlengine); + QScriptValue prog = engine->evaluate(GLOBALPROPERTY_PROGRAM); + prog.call(); + + QBENCHMARK { + prog.call(); + } +} + +void tst_script::global_property_qml_js() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, TEST_FILE("global_prop.qml")); + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle *>(component.create()); + QVERIFY(rect != 0); + + int index = rect->metaObject()->indexOfMethod("triggered()"); + QVERIFY(index != -1); + QMetaMethod method = rect->metaObject()->method(index); + + QBENCHMARK { + method.invoke(rect, Qt::DirectConnection); + } + + delete rect; +} + +void tst_script::scriptfile_property() +{ + QDeclarativeEngine engine; + QDeclarativeComponent component(&engine, TEST_FILE("global_prop.qml")); + QDeclarativeRectangle *rect = qobject_cast<QDeclarativeRectangle *>(component.create()); + QVERIFY(rect != 0); + + int index = rect->metaObject()->indexOfMethod("incrementTriggered()"); + QVERIFY(index != -1); + QMetaMethod method = rect->metaObject()->method(index); + + QBENCHMARK { + method.invoke(rect, Qt::DirectConnection); + } + + delete rect; +} + QTEST_MAIN(tst_script) #include "tst_script.moc" diff --git a/tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp b/tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp index 8e9de4a..27e5025 100644 --- a/tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp +++ b/tests/benchmarks/gui/image/qpixmap/tst_qpixmap.cpp @@ -40,9 +40,12 @@ ****************************************************************************/ #include <qtest.h> -#include <QPixmap> #include <QBitmap> +#include <QDir> +#include <QImage> +#include <QImageReader> #include <QPainter> +#include <QPixmap> #include <private/qpixmap_raster_p.h> class tst_QPixmap : public QObject @@ -62,6 +65,9 @@ private slots: void transformed(); void mask_data(); void mask(); + + void fromImageReader_data(); + void fromImageReader(); }; Q_DECLARE_METATYPE(QImage::Format) @@ -248,6 +254,62 @@ void tst_QPixmap::mask() } } +void tst_QPixmap::fromImageReader_data() +{ + const QString tempDir = QDir::tempPath(); + QTest::addColumn<QString>("filename"); + + QImage image(2000, 2000, QImage::Format_ARGB32); + image.fill(0); + { + // Generate an image with opaque and transparent pixels + // with an interesting distribution. + QPainter painter(&image); + + QRadialGradient radialGrad(QPointF(1000, 1000), 1000); + radialGrad.setColorAt(0, QColor(255, 0, 0, 255)); + radialGrad.setColorAt(0.5, QColor(0, 255, 0, 255)); + radialGrad.setColorAt(0.9, QColor(0, 0, 255, 100)); + radialGrad.setColorAt(1, QColor(0, 0, 0, 0)); + + painter.fillRect(image.rect(), radialGrad); + } + image.save("test.png"); + + // RGB32 + const QString rgb32Path = tempDir + QString::fromLatin1("/rgb32.jpg"); + image.save(rgb32Path); + QTest::newRow("gradient RGB32") << rgb32Path; + + // ARGB32 + const QString argb32Path = tempDir + QString::fromLatin1("/argb32.png"); + image.save(argb32Path); + QTest::newRow("gradient ARGB32") << argb32Path; + + // Indexed 8 + const QString indexed8Path = tempDir + QString::fromLatin1("/indexed8.gif"); + image.save(indexed8Path); + QTest::newRow("gradient indexed8") << indexed8Path; + +} + +void tst_QPixmap::fromImageReader() +{ + QFETCH(QString, filename); + // warmup + { + QImageReader imageReader(filename); + QPixmap::fromImageReader(&imageReader); + } + + QBENCHMARK { + QImageReader imageReader(filename); + QPixmap::fromImageReader(&imageReader); + } + QFile::remove(filename); +} + + QTEST_MAIN(tst_QPixmap) #include "tst_qpixmap.moc" diff --git a/tests/benchmarks/gui/text/qtext/main.cpp b/tests/benchmarks/gui/text/qtext/main.cpp index d4f3165..63daae0 100644 --- a/tests/benchmarks/gui/text/qtext/main.cpp +++ b/tests/benchmarks/gui/text/qtext/main.cpp @@ -82,7 +82,13 @@ private slots: void constructControl(); void constructDocument(); + void newLineReplacement(); + void formatManipulation(); + void fontResolution(); + + void layout_data(); void layout(); + void formattedLayout(); void paintLayoutToPixmap(); void paintLayoutToPixmap_painterFill(); @@ -95,7 +101,7 @@ private slots: void paintControlToPixmap_painterFill(); private: - QSize setupTextLayout(QTextLayout *layout); + QSize setupTextLayout(QTextLayout *layout, bool wrap = true, int wrapWidth = 100); QString m_lorem; QString m_shortLorem; @@ -227,10 +233,8 @@ void tst_QText::odfWriting_images() delete doc; } -QSize tst_QText::setupTextLayout(QTextLayout *layout) +QSize tst_QText::setupTextLayout(QTextLayout *layout, bool wrap, int wrapWidth) { - bool wrap = true; - int wrapWidth = 300; layout->setCacheEnabled(true); int height = 0; @@ -242,7 +246,6 @@ QSize tst_QText::setupTextLayout(QTextLayout *layout) lineWidth = wrapWidth; layout->beginLayout(); - while (1) { QTextLine line = layout->createLine(); if (!line.isValid()) @@ -284,13 +287,95 @@ void tst_QText::constructDocument() } } +//this step is needed before giving the string to a QTextLayout +void tst_QText::newLineReplacement() +{ + QString text = QString::fromLatin1("H\ne\nl\nl\no\n\nW\no\nr\nl\nd"); + + QBENCHMARK { + QString tmp = text; + tmp.replace(QLatin1Char('\n'), QChar::LineSeparator); + } +} + +void tst_QText::formatManipulation() +{ + QFont font; + + QBENCHMARK { + QTextCharFormat format; + format.setFont(font); + } +} + +void tst_QText::fontResolution() +{ + QFont font; + QFont font2; + font.setFamily("DejaVu"); + font2.setBold(true); + + QBENCHMARK { + QFont res = font.resolve(font2); + } +} + +void tst_QText::layout_data() +{ + QTest::addColumn<bool>("wrap"); + QTest::newRow("wrap") << true; + QTest::newRow("nowrap") << false; +} + void tst_QText::layout() { + QFETCH(bool,wrap); + QTextLayout layout(m_shortLorem); + setupTextLayout(&layout, wrap); + + QBENCHMARK { + QTextLayout layout(m_shortLorem); + setupTextLayout(&layout, wrap); + } +} + +//### requires tst_QText to be a friend of QTextLayout +/*void tst_QText::stackTextLayout() +{ + QStackTextEngine engine(m_shortLorem, qApp->font()); + QTextLayout layout(&engine); + setupTextLayout(&layout); + + QBENCHMARK { + QStackTextEngine engine(m_shortLorem, qApp->font()); + QTextLayout layout(&engine); + setupTextLayout(&layout); + } +}*/ + +void tst_QText::formattedLayout() +{ + //set up formatting + QList<QTextLayout::FormatRange> ranges; + { + QTextCharFormat format; + format.setForeground(QColor("steelblue")); + + QTextLayout::FormatRange formatRange; + formatRange.format = format; + formatRange.start = 0; + formatRange.length = 50; + + ranges.append(formatRange); + } + QTextLayout layout(m_shortLorem); + layout.setAdditionalFormats(ranges); setupTextLayout(&layout); QBENCHMARK { QTextLayout layout(m_shortLorem); + layout.setAdditionalFormats(ranges); setupTextLayout(&layout); } } diff --git a/tests/benchmarks/opengl/main.cpp b/tests/benchmarks/opengl/main.cpp index beb4d43..c042fce 100644 --- a/tests/benchmarks/opengl/main.cpp +++ b/tests/benchmarks/opengl/main.cpp @@ -75,6 +75,10 @@ private slots: void gradients_data(); void gradients(); + void textureUpload_data(); + void textureUpload(); + + private: QGLPixelBuffer *pb; }; @@ -374,6 +378,53 @@ void OpenGLBench::gradients() } } +void OpenGLBench::textureUpload_data() +{ + QTest::addColumn<int>("size"); + QTest::addColumn<int>("flags"); + QTest::addColumn<int>("format"); + + int sizes[] = { 8, 10, 16, 20, 32, 50, 64, 100, 128, 200, 256, 500, 512, 1000, 1024, 2000, 2048, -1 }; + int flags[] = { QGLContext::InternalBindOption, + QGLContext::DefaultBindOption, + -1 }; + int formats[] = { GL_RGB, GL_RGBA, -1 }; + + for (int s = 0; sizes[s] != -1; ++s) { + for (int f = 0; flags[f] != -1; ++f) { + for (int a = 0; formats[a] != -1; ++a) { + QByteArray name; + name.append("size=").append(QByteArray::number(sizes[s])); + name.append(", flags=").append(f == 0 ? "internal" : "default"); + name.append(", format=").append(a == 0 ? "RGB" : "RGBA"); + QTest::newRow(name.constData()) << sizes[s] << flags[f] << formats[a]; + } + } + } +} + +void OpenGLBench::textureUpload() +{ + QFETCH(int, size); + QFETCH(int, flags); + QFETCH(int, format); + + QPixmap pixmap(size, size); + + if (format == GL_RGB) + pixmap.fill(Qt::red); + else + pixmap.fill(Qt::transparent); + + pb->makeCurrent(); + QGLContext *context = const_cast<QGLContext *>(QGLContext::currentContext()); + QTime time; + + time.start(); + context->bindTexture(pixmap, GL_TEXTURE_2D, format, (QGLContext::BindOptions) flags); + QTest::setBenchmarkResult(time.elapsed(), QTest::WalltimeMilliseconds); +} + QTEST_MAIN(OpenGLBench) #include "main.moc" |