diff options
author | axis <qt-info@nokia.com> | 2011-02-24 16:07:22 (GMT) |
---|---|---|
committer | axis <qt-info@nokia.com> | 2011-02-24 16:07:22 (GMT) |
commit | 2b768ad7d4de4862584762a7d106d9cfcc3416df (patch) | |
tree | 0ddfe84f345d7e61ce71daa51fbbfb373c3e3106 /tests/benchmarks | |
parent | bb7d9bcc8e0c617091e91f7a40f3d33f8c1cdec1 (diff) | |
parent | ca7be48b7a150952a9657d1000941fb986e5bb2b (diff) | |
download | Qt-2b768ad7d4de4862584762a7d106d9cfcc3416df.zip Qt-2b768ad7d4de4862584762a7d106d9cfcc3416df.tar.gz Qt-2b768ad7d4de4862584762a7d106d9cfcc3416df.tar.bz2 |
Merge branch 'master' of scm.dev.nokia.troll.no:qt/qt into earth-master
Conflicts:
src/network/access/qnetworkreplyimpl.cpp
tests/auto/moc/tst_moc.cpp
Diffstat (limited to 'tests/benchmarks')
19 files changed, 470 insertions, 2 deletions
diff --git a/tests/benchmarks/corelib/corelib.pro b/tests/benchmarks/corelib/corelib.pro index 335280e..a2efe91 100644 --- a/tests/benchmarks/corelib/corelib.pro +++ b/tests/benchmarks/corelib/corelib.pro @@ -11,6 +11,7 @@ TRUSTED_BENCHMARKS += \ kernel/qmetaobject \ kernel/qmetatype \ kernel/qobject \ - thread/qthreadstorage + thread/qthreadstorage \ + io/qdir/tree include(../trusted-benchmarks.pri)
\ No newline at end of file diff --git a/tests/benchmarks/declarative/qperformancetimer/qperformancetimer.pro b/tests/benchmarks/declarative/qperformancetimer/qperformancetimer.pro new file mode 100644 index 0000000..a39cd3d --- /dev/null +++ b/tests/benchmarks/declarative/qperformancetimer/qperformancetimer.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +QT += declarative +TEMPLATE = app +TARGET = tst_qperformancetimer +macx:CONFIG -= app_bundle + +SOURCES += tst_qperformancetimer.cpp + diff --git a/tests/benchmarks/declarative/qperformancetimer/tst_qperformancetimer.cpp b/tests/benchmarks/declarative/qperformancetimer/tst_qperformancetimer.cpp new file mode 100644 index 0000000..497a556 --- /dev/null +++ b/tests/benchmarks/declarative/qperformancetimer/tst_qperformancetimer.cpp @@ -0,0 +1,100 @@ +/**************************************************************************** +** +** 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$ +** +****************************************************************************/ + +#include <private/qperformancetimer_p.h> +#include <QObject> +#include <qtest.h> + +class tst_qperformancetimer : public QObject +{ + Q_OBJECT + +public: + tst_qperformancetimer() {} + +private slots: + void all(); + void startElapsed(); + void doubleElapsed(); + void trace(); +}; + +void tst_qperformancetimer::all() +{ + QBENCHMARK { + QPerformanceTimer t; + t.start(); + t.elapsed(); + } +} + +void tst_qperformancetimer::startElapsed() +{ + QPerformanceTimer t; + QBENCHMARK { + t.start(); + t.elapsed(); + } +} + +void tst_qperformancetimer::doubleElapsed() +{ + QPerformanceTimer t; + t.start(); + QBENCHMARK { + t.elapsed(); + t.elapsed(); + } +} + +void tst_qperformancetimer::trace() +{ + QString s("A decent sized string of text here."); + QBENCHMARK { + QByteArray data; + QDataStream ds(&data, QIODevice::WriteOnly); + ds << (qint64)100 << (int)5 << (int)5 << s; + } +} + +QTEST_MAIN(tst_qperformancetimer) + +#include "tst_qperformancetimer.moc" diff --git a/tests/benchmarks/script/context2d/context2d.pro b/tests/benchmarks/script/context2d/context2d.pro new file mode 100644 index 0000000..bc94c4f --- /dev/null +++ b/tests/benchmarks/script/context2d/context2d.pro @@ -0,0 +1,22 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_context2d + +SOURCES += tst_context2d.cpp + +CONTEXT2D_EXAMPLE_DIR = $$QT_SOURCE_TREE/examples/script/context2d +INCLUDEPATH += $$CONTEXT2D_EXAMPLE_DIR + +HEADERS += $$CONTEXT2D_EXAMPLE_DIR/qcontext2dcanvas.h \ + $$CONTEXT2D_EXAMPLE_DIR/context2d.h \ + $$CONTEXT2D_EXAMPLE_DIR/domimage.h \ + $$CONTEXT2D_EXAMPLE_DIR/environment.h + +SOURCES += $$CONTEXT2D_EXAMPLE_DIR/qcontext2dcanvas.cpp \ + $$CONTEXT2D_EXAMPLE_DIR/context2d.cpp \ + $$CONTEXT2D_EXAMPLE_DIR/domimage.cpp \ + $$CONTEXT2D_EXAMPLE_DIR/environment.cpp + +RESOURCES += $$CONTEXT2D_EXAMPLE_DIR/context2d.qrc + +QT += script diff --git a/tests/benchmarks/script/context2d/tst_context2d.cpp b/tests/benchmarks/script/context2d/tst_context2d.cpp new file mode 100644 index 0000000..8401590 --- /dev/null +++ b/tests/benchmarks/script/context2d/tst_context2d.cpp @@ -0,0 +1,177 @@ +/**************************************************************************** +** +** 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/qdir.h> +#include <QtCore/qfile.h> +#include <QtCore/qtextstream.h> +#include <QtScript/qscriptengine.h> +#include <QtScript/qscriptvalue.h> +#include "context2d.h" +#include "environment.h" +#include "qcontext2dcanvas.h" + +static QString readFile(const QString &filename) +{ + QFile file(filename); + if (!file.open(QFile::ReadOnly)) + return QString(); + QTextStream stream(&file); + stream.setCodec("UTF-8"); + return stream.readAll(); +} + +class tst_Context2D : public QObject +{ + Q_OBJECT + +public: + tst_Context2D(); + ~tst_Context2D(); + +private slots: + void singleExecution_data(); + void singleExecution(); + void repeatedExecution_data(); + void repeatedExecution(); + +private: + void newEnvironment(); + +private: + QDir testsDir; + Environment *m_env; + QContext2DCanvas *m_canvas; +}; + +tst_Context2D::tst_Context2D() + : m_env(0), m_canvas(0) +{ + testsDir = QDir(":/scripts"); + if (!testsDir.exists()) + qWarning("*** no scripts/ dir!"); +} + +tst_Context2D::~tst_Context2D() +{ + delete m_canvas; + delete m_env; +} + +void tst_Context2D::newEnvironment() +{ + delete m_canvas; + delete m_env; + m_env = new Environment(); + Context2D *context = new Context2D(m_env); + context->setSize(150, 150); // Hard-coded in many of the scripts. + m_canvas = new QContext2DCanvas(context, m_env); + m_canvas->setFixedSize(context->size()); + m_canvas->setObjectName("tutorial"); // Acts as the DOM element ID. + m_env->addCanvas(m_canvas); +} + +void tst_Context2D::singleExecution_data() +{ + QTest::addColumn<QString>("testName"); + QFileInfoList testFileInfos = testsDir.entryInfoList(QStringList() << "*.js", QDir::Files); + foreach (QFileInfo tfi, testFileInfos) { + QString name = tfi.baseName(); + QTest::newRow(name.toLatin1().constData()) << name; + } +} + +void tst_Context2D::singleExecution() +{ + QFETCH(QString, testName); + QString script = readFile(testsDir.absoluteFilePath(testName + ".js")); + QVERIFY(!script.isEmpty()); + + newEnvironment(); + QBENCHMARK { + m_env->evaluate(script, testName); + // Some of the scripts (e.g. plasma.js) merely start a timer and do + // the actual drawing in the timer event. Trigger the timers now to + // ensure that the real work is done. + m_env->triggerTimers(); + } + QVERIFY(!m_env->engine()->hasUncaughtException()); +} + +void tst_Context2D::repeatedExecution_data() +{ + // We look for scripts that register an interval timer. + // Such scripts run a function every n milliseconds to update the canvas. + // The benchmark will execute this function repeatedly, which can allow + // us to observe potential effects of profiling-based JIT optimizations. + QTest::addColumn<QString>("testName"); + QTest::addColumn<QString>("script"); + QFileInfoList testFileInfos = testsDir.entryInfoList(QStringList() << "*.js", QDir::Files); + foreach (QFileInfo tfi, testFileInfos) { + QString script = readFile(tfi.absoluteFilePath()); + QString name = tfi.baseName(); + newEnvironment(); + m_env->evaluate(script, name); + if (m_env->engine()->hasUncaughtException()) + continue; + if (m_env->hasIntervalTimers()) + QTest::newRow(name.toLatin1().constData()) << name << script; + } +} + +void tst_Context2D::repeatedExecution() +{ + QFETCH(QString, testName); + QFETCH(QString, script); + + newEnvironment(); + m_env->evaluate(script, testName); + QBENCHMARK { + // Trigger the update function repeatedly, effectively + // performing several frames of animation. + for (int i = 0; i < 16; ++i) + m_env->triggerTimers(); + } + QVERIFY(!m_env->engine()->hasUncaughtException()); +} + +QTEST_MAIN(tst_Context2D) +#include "tst_context2d.moc" diff --git a/tests/benchmarks/script/qscriptclass_bytearray/qscriptclass_bytearray.pro b/tests/benchmarks/script/qscriptclass_bytearray/qscriptclass_bytearray.pro new file mode 100644 index 0000000..d64f705 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/qscriptclass_bytearray.pro @@ -0,0 +1,10 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_qscriptclass_bytearray + +SOURCES += tst_qscriptclass_bytearray.cpp +RESOURCES += qscriptclass_bytearray.qrc + +include($$QT_SOURCE_TREE/examples/script/customclass/bytearrayclass.pri) + +QT = core script diff --git a/tests/benchmarks/script/qscriptclass_bytearray/qscriptclass_bytearray.qrc b/tests/benchmarks/script/qscriptclass_bytearray/qscriptclass_bytearray.qrc new file mode 100644 index 0000000..a894ee5 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/qscriptclass_bytearray.qrc @@ -0,0 +1,5 @@ +<!DOCTYPE RCC><RCC version="1.0"> +<qresource> + <file>tests</file> +</qresource> +</RCC> diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tests/construct-copy.js b/tests/benchmarks/script/qscriptclass_bytearray/tests/construct-copy.js new file mode 100644 index 0000000..9c03871 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tests/construct-copy.js @@ -0,0 +1,3 @@ +ba = new ByteArray(123); +for (i = 0; i < 5000; ++i) + new ByteArray(ba); diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tests/construct.js b/tests/benchmarks/script/qscriptclass_bytearray/tests/construct.js new file mode 100644 index 0000000..2c2bbf5 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tests/construct.js @@ -0,0 +1,2 @@ +for (i = 0; i < 5000; ++i) + new ByteArray(123); diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tests/for-in.js b/tests/benchmarks/script/qscriptclass_bytearray/tests/for-in.js new file mode 100644 index 0000000..46bc9f3 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tests/for-in.js @@ -0,0 +1,3 @@ +ba = new ByteArray(8000); +for (var p in ba) + ; diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tests/get-element.js b/tests/benchmarks/script/qscriptclass_bytearray/tests/get-element.js new file mode 100644 index 0000000..9f6a503 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tests/get-element.js @@ -0,0 +1,3 @@ +ba = new ByteArray(123); +for (i = 0; i < 10000; ++i) + ba[10]; diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tests/get-length.js b/tests/benchmarks/script/qscriptclass_bytearray/tests/get-length.js new file mode 100644 index 0000000..5de2f58 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tests/get-length.js @@ -0,0 +1,3 @@ +ba = new ByteArray(123); +for (i = 0; i < 10000; ++i) + ba.length; diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tests/mid.js b/tests/benchmarks/script/qscriptclass_bytearray/tests/mid.js new file mode 100644 index 0000000..752d875 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tests/mid.js @@ -0,0 +1,3 @@ +ba = new ByteArray(123); +for (i = 0; i < 3000; ++i) + ba.mid(50); diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tests/set-element.js b/tests/benchmarks/script/qscriptclass_bytearray/tests/set-element.js new file mode 100644 index 0000000..4883765 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tests/set-element.js @@ -0,0 +1,3 @@ +ba = new ByteArray(123); +for (i = 0; i < 10000; ++i) + ba[10] = 123; diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tests/set-length.js b/tests/benchmarks/script/qscriptclass_bytearray/tests/set-length.js new file mode 100644 index 0000000..18c9f59 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tests/set-length.js @@ -0,0 +1,3 @@ +ba = new ByteArray(); +for (i = 0; i < 10000; ++i) + ba.length = 123; diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tests/sum.js b/tests/benchmarks/script/qscriptclass_bytearray/tests/sum.js new file mode 100644 index 0000000..096937d --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tests/sum.js @@ -0,0 +1,8 @@ +function sum(ba) { + var result = 0; + for (var i = 0; i < ba.length; ++i) + result += ba[i]; + return result; +} + +sum(new ByteArray(10000)); diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tests/trimmed.js b/tests/benchmarks/script/qscriptclass_bytearray/tests/trimmed.js new file mode 100644 index 0000000..967dba6 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tests/trimmed.js @@ -0,0 +1,3 @@ +ba = new ByteArray(123); +for (i = 0; i < 3000; ++i) + ba.trimmed(); diff --git a/tests/benchmarks/script/qscriptclass_bytearray/tst_qscriptclass_bytearray.cpp b/tests/benchmarks/script/qscriptclass_bytearray/tst_qscriptclass_bytearray.cpp new file mode 100644 index 0000000..351adc8 --- /dev/null +++ b/tests/benchmarks/script/qscriptclass_bytearray/tst_qscriptclass_bytearray.cpp @@ -0,0 +1,109 @@ +/**************************************************************************** +** +** 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/qdir.h> +#include <QtCore/qfile.h> +#include <QtCore/qtextstream.h> +#include <QtScript/qscriptengine.h> +#include <QtScript/qscriptvalue.h> +#include "bytearrayclass.h" + +static QString readFile(const QString &filename) +{ + QFile file(filename); + if (!file.open(QFile::ReadOnly)) + return QString(); + QTextStream stream(&file); + stream.setCodec("UTF-8"); + return stream.readAll(); +} + +class tst_QScriptClass_ByteArray : public QObject +{ + Q_OBJECT + +public: + tst_QScriptClass_ByteArray(); + +private slots: + void benchmark_data(); + void benchmark(); + +private: + QDir testsDir; +}; + +tst_QScriptClass_ByteArray::tst_QScriptClass_ByteArray() +{ + testsDir = QDir(":/tests"); + if (!testsDir.exists()) + qWarning("*** no tests/ dir!"); +} + +void tst_QScriptClass_ByteArray::benchmark_data() +{ + QTest::addColumn<QString>("testName"); + QFileInfoList testFileInfos = testsDir.entryInfoList(QStringList() << "*.js", QDir::Files); + foreach (QFileInfo tfi, testFileInfos) { + QString name = tfi.baseName(); + QTest::newRow(name.toLatin1().constData()) << name; + } +} + +void tst_QScriptClass_ByteArray::benchmark() +{ + QFETCH(QString, testName); + QString testContents = readFile(testsDir.absoluteFilePath(testName + ".js")); + QVERIFY(!testContents.isEmpty()); + + QScriptEngine eng; + ByteArrayClass *baClass = new ByteArrayClass(&eng); + eng.globalObject().setProperty("ByteArray", baClass->constructor()); + + QBENCHMARK { + eng.evaluate(testContents); + } + QVERIFY(!eng.hasUncaughtException()); +} + +QTEST_MAIN(tst_QScriptClass_ByteArray) +#include "tst_qscriptclass_bytearray.moc" diff --git a/tests/benchmarks/script/script.pro b/tests/benchmarks/script/script.pro index b0770ca..d4fc822 100644 --- a/tests/benchmarks/script/script.pro +++ b/tests/benchmarks/script/script.pro @@ -1,6 +1,8 @@ TEMPLATE = subdirs SUBDIRS = \ + context2d \ qscriptclass \ + qscriptclass_bytearray \ qscriptengine \ qscriptvalue \ sunspider \ @@ -13,4 +15,4 @@ TRUSTED_BENCHMARKS += \ qscriptvalue \ qscriptengine -include(../trusted-benchmarks.pri)
\ No newline at end of file +include(../trusted-benchmarks.pri) |