summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/script
diff options
context:
space:
mode:
authorKent Hansen <kent.hansen@nokia.com>2011-02-04 08:39:10 (GMT)
committerKent Hansen <kent.hansen@nokia.com>2011-02-04 11:14:06 (GMT)
commitb0c109ff2479dd8f4474b6c5ad537168224a5dc4 (patch)
tree1574f766bd31f29666c8af8ec27f13555f1bcfcb /tests/benchmarks/script
parent6163c36249eea0a2a578b9990470fcaa2f7bcf5f (diff)
downloadQt-b0c109ff2479dd8f4474b6c5ad537168224a5dc4.zip
Qt-b0c109ff2479dd8f4474b6c5ad537168224a5dc4.tar.gz
Qt-b0c109ff2479dd8f4474b6c5ad537168224a5dc4.tar.bz2
Add QScriptClass/ByteArray benchmark
Reuse the ByteArray implementation from examples/script/customclass and create a benchmark out of it. This benchmark actually measures a meaningful, real-world use case for QScriptClass. Task-number: QTBUG-17192 Reviewed-by: Jedrzej Nowacki
Diffstat (limited to 'tests/benchmarks/script')
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/qscriptclass_bytearray.pro10
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/qscriptclass_bytearray.qrc5
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tests/construct-copy.js3
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tests/construct.js2
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tests/for-in.js3
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tests/get-element.js3
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tests/get-length.js3
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tests/mid.js3
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tests/set-element.js3
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tests/set-length.js3
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tests/sum.js8
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tests/trimmed.js3
-rw-r--r--tests/benchmarks/script/qscriptclass_bytearray/tst_qscriptclass_bytearray.cpp109
-rw-r--r--tests/benchmarks/script/script.pro1
14 files changed, 159 insertions, 0 deletions
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 da7a5a1..d4fc822 100644
--- a/tests/benchmarks/script/script.pro
+++ b/tests/benchmarks/script/script.pro
@@ -2,6 +2,7 @@ TEMPLATE = subdirs
SUBDIRS = \
context2d \
qscriptclass \
+ qscriptclass_bytearray \
qscriptengine \
qscriptvalue \
sunspider \