summaryrefslogtreecommitdiff
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorMichael Brasser <michael.brasser@nokia.com>2011-03-16 10:23:06 +1000
committerMichael Brasser <michael.brasser@nokia.com>2011-03-16 12:51:46 +1000
commit99512251be8e5814238ec398854a8aa71fa8b25d (patch)
treecdaba27de02a9aadc1b61ab8dd3ea36b25e58a7d /tests/benchmarks
parent82ae515e52e3811d3b2aec588e0dd777350c1c33 (diff)
downloadqt4-tools-99512251be8e5814238ec398854a8aa71fa8b25d.tar.gz
Optimization and benchmark for setting object properties from QML.
Change-Id: Ib923e5d3946e99001ef682a9dd8ca6d7788818a3 Reviewed-by: Aaron Kennedy
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/declarative/script/tst_script.cpp49
1 files changed, 48 insertions, 1 deletions
diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp
index 2020a18440..b07ffa101b 100644
--- a/tests/benchmarks/declarative/script/tst_script.cpp
+++ b/tests/benchmarks/declarative/script/tst_script.cpp
@@ -70,6 +70,9 @@ private slots:
void property_qobject();
void property_qmlobject();
+ void setproperty_js();
+ void setproperty_qmlobject();
+
void function_js();
void function_cpp();
void function_qobject();
@@ -108,12 +111,13 @@ inline QUrl TEST_FILE(const QString &filename)
class TestObject : public QObject
{
Q_OBJECT
- Q_PROPERTY(int x READ x)
+ Q_PROPERTY(int x READ x WRITE setX)
public:
TestObject(QObject *parent = 0);
int x();
+ void setX(int x) { m_x = x; }
void emitMySignal() { emit mySignal(); }
void emitMySignalWithArgs(int n) { emit mySignalWithArgs(n); }
@@ -323,6 +327,49 @@ void tst_script::property_qmlobject()
}
}
+#define SETPROPERTY_PROGRAM \
+ "(function(testObject) { return (function() { " \
+ " for (var ii = 0; ii < 10000; ++ii) { " \
+ " testObject.x = ii; " \
+ " } " \
+ "}); })"
+
+void tst_script::setproperty_js()
+{
+ QScriptEngine engine;
+
+ QScriptValue v = engine.newObject();
+ v.setProperty(QLatin1String("x"), 0);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine.evaluate(SETPROPERTY_PROGRAM).call(engine.globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
+void tst_script::setproperty_qmlobject()
+{
+ QDeclarativeEngine qmlengine;
+
+ QScriptEngine *engine = QDeclarativeEnginePrivate::getScriptEngine(&qmlengine);
+ TestObject to;
+
+ QScriptValue v = QDeclarativeEnginePrivate::get(&qmlengine)->objectClass->newQObject(&to);
+
+ QScriptValueList args;
+ args << v;
+ QScriptValue prog = engine->evaluate(SETPROPERTY_PROGRAM).call(engine->globalObject(), args);
+ prog.call();
+
+ QBENCHMARK {
+ prog.call();
+ }
+}
+
#define FUNCTION_PROGRAM \
"(function(testObject) { return (function() { " \
" var test = 0; " \