diff options
author | Michael Brasser <michael.brasser@nokia.com> | 2010-01-27 00:04:54 (GMT) |
---|---|---|
committer | Michael Brasser <michael.brasser@nokia.com> | 2010-01-27 00:04:54 (GMT) |
commit | 167cbed98b5d9fadbe5d6f506e3937a25e7189b1 (patch) | |
tree | 3975f6add25a125d175d2f9d64c5e5491fc652c5 /tests/benchmarks | |
parent | 9df62fe28e0d2bec39d7c4917ec8d193e23465dd (diff) | |
download | Qt-167cbed98b5d9fadbe5d6f506e3937a25e7189b1.zip Qt-167cbed98b5d9fadbe5d6f506e3937a25e7189b1.tar.gz Qt-167cbed98b5d9fadbe5d6f506e3937a25e7189b1.tar.bz2 |
Benchmark performance of a block of script containing multiple property accesses.
Diffstat (limited to 'tests/benchmarks')
-rw-r--r-- | tests/benchmarks/declarative/script/data/CustomObject.qml | 7 | ||||
-rw-r--r-- | tests/benchmarks/declarative/script/data/block.qml | 34 | ||||
-rw-r--r-- | tests/benchmarks/declarative/script/tst_script.cpp | 31 |
3 files changed, 72 insertions, 0 deletions
diff --git a/tests/benchmarks/declarative/script/data/CustomObject.qml b/tests/benchmarks/declarative/script/data/CustomObject.qml new file mode 100644 index 0000000..22b7be7 --- /dev/null +++ b/tests/benchmarks/declarative/script/data/CustomObject.qml @@ -0,0 +1,7 @@ +import Qt 4.6 + +QtObject { + property real prop1: 0 + property real prop2: 1 + property real prop3: 0 +} diff --git a/tests/benchmarks/declarative/script/data/block.qml b/tests/benchmarks/declarative/script/data/block.qml new file mode 100644 index 0000000..bb03d8d --- /dev/null +++ b/tests/benchmarks/declarative/script/data/block.qml @@ -0,0 +1,34 @@ +import Qt 4.6 + +Rectangle { + width: 200; height: 200 + CustomObject { id: theObject } + function doSomethingDirect() { + theObject.prop1 = 0; + + for (var i = 0; i < 60; ++i) + theObject.prop1 += theObject.prop2; + + theObject.prop3 = theObject.prop1; + } + + function doSomethingLocalObj() { + theObject.prop1 = 0; + + var incrementObj = theObject; + for (var i = 0; i < 60; ++i) + incrementObj.prop1 += incrementObj.prop2; + + incrementObj.prop3 = incrementObj.prop1; + } + + function doSomethingLocal() { + theObject.prop1 = 0; + + var increment = theObject.prop2; + for (var i = 0; i < 60; ++i) + theObject.prop1 += increment; + + theObject.prop3 = theObject.prop1; + } +} diff --git a/tests/benchmarks/declarative/script/tst_script.cpp b/tests/benchmarks/declarative/script/tst_script.cpp index f417d0c..36a0833 100644 --- a/tests/benchmarks/declarative/script/tst_script.cpp +++ b/tests/benchmarks/declarative/script/tst_script.cpp @@ -44,6 +44,7 @@ #include <QmlComponent> #include <private/qmlengine_p.h> #include <private/qmlobjectscriptclass_p.h> +#include <private/qmlgraphicsrectangle_p.h> #include <QScriptEngine> #include <QScriptValue> @@ -81,6 +82,9 @@ private slots: void slot_simple_js(); void slot_complex(); void slot_complex_js(); + + void block_data(); + void block(); private: }; @@ -582,6 +586,33 @@ void tst_script::slot_complex_js() delete object; } +void tst_script::block_data() +{ + QTest::addColumn<QString>("methodName"); + QTest::newRow("direct") << "doSomethingDirect()"; + QTest::newRow("localObj") << "doSomethingLocalObj()"; + QTest::newRow("local") << "doSomethingLocal()"; +} + +void tst_script::block() +{ + QFETCH(QString, methodName); + QmlEngine engine; + QmlComponent component(&engine, TEST_FILE("block.qml")); + QmlGraphicsRectangle *rect = qobject_cast<QmlGraphicsRectangle *>(component.create()); + QVERIFY(rect != 0); + + int index = rect->metaObject()->indexOfMethod(methodName.toUtf8()); + 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" |