From 25568c9d01e5ace5557c9aebc42d0de3cf2873e4 Mon Sep 17 00:00:00 2001 From: Milian Wolff Date: Thu, 19 Dec 2013 16:46:40 +0100 Subject: Port MetaObjectPublisher benchmarks to C++. This allows us to remove the public API for the tests and allows for more tests and benchmarks in the future. To achieve this, we re-use the new qmetaobjectpublisher_p.h, which then also must be exported. Change-Id: I3c33b2f5be6cc674cd3092667151dd8da2263cf5 Reviewed-by: Zeno Albisser --- tests/qml/tst_bench.qml | 35 ------------- tests/webchannel/tst_webchannel.cpp | 96 ++++++++++++++++++++++++++++++++++++ tests/webchannel/tst_webchannel.h | 97 +++++++++++++++++++++++++++++++++++++ 3 files changed, 193 insertions(+), 35 deletions(-) (limited to 'tests') diff --git a/tests/qml/tst_bench.qml b/tests/qml/tst_bench.qml index 6893a00..46eb6be 100644 --- a/tests/qml/tst_bench.qml +++ b/tests/qml/tst_bench.qml @@ -100,41 +100,6 @@ WebChannelTest { publisher.registerObjects(objects); } - function benchmark_classInfo() - { - publisher.classInfoForObjects(objects); - } - - function benchmark_initializeClients() - { - publisher.bench_initializeClients(); - } - - function benchmark_propertyUpdates() - { - // required to make the benchmark work standalone - publisher.bench_ensureUpdatesInitialized(); - - for (var o in objects) { - objects[o].p0++; - objects[o].p1++; - objects[o].p2++; - objects[o].p3++; - objects[o].p4++; - objects[o].p5++; - objects[o].p6++; - objects[o].p7++; - objects[o].p8++; - objects[o].p9++; - } - publisher.bench_sendPendingPropertyUpdates(); - } - - function benchmark_registerObjects() - { - publisher.bench_registerObjects(objects); - } - function benchmark_init_baseline() { loadUrl("bench_init.html"); diff --git a/tests/webchannel/tst_webchannel.cpp b/tests/webchannel/tst_webchannel.cpp index c1f23d1..e997bd7 100644 --- a/tests/webchannel/tst_webchannel.cpp +++ b/tests/webchannel/tst_webchannel.cpp @@ -44,6 +44,7 @@ #include #include +#include #include @@ -145,4 +146,99 @@ void TestWebChannel::testInfoForObject() } } +static QVariantMap createObjects(QObject *parent) +{ + const int num = 100; + QVariantMap objects; + for (int i = 0; i < num; ++i) { + objects[QStringLiteral("obj%1").arg(i)] = QVariant::fromValue(new BenchObject(parent)); + } + return objects; +} + +void TestWebChannel::benchClassInfo() +{ + QWebChannel channel; + QSignalSpy initSpy(&channel, SIGNAL(initialized())); + QVERIFY(initSpy.wait()); + + QMetaObjectPublisher publisher; + publisher.setWebChannel(&channel); + + QObject parent; + const QVariantMap objects = createObjects(&parent); + + QBENCHMARK { + publisher.classInfoForObjects(objects); + } +} + +void TestWebChannel::benchInitializeClients() +{ + QWebChannel channel; + QSignalSpy initSpy(&channel, SIGNAL(initialized())); + QVERIFY(initSpy.wait()); + + QMetaObjectPublisher publisher; + publisher.setWebChannel(&channel); + + QObject parent; + const QVariantMap objects = createObjects(&parent); + publisher.registerObjects(objects); + + QBENCHMARK { + publisher.d->initializeClients(); + + publisher.d->propertyUpdatesInitialized = false; + publisher.d->signalToPropertyMap.clear(); + publisher.d->signalHandler.clear(); + } +} + +void TestWebChannel::benchPropertyUpdates() +{ + QWebChannel channel; + QSignalSpy initSpy(&channel, SIGNAL(initialized())); + QVERIFY(initSpy.wait()); + + QMetaObjectPublisher publisher; + publisher.setWebChannel(&channel); + + QObject parent; + const QVariantMap objects = createObjects(&parent); + QVector objectList; + foreach (const QVariant &var, objects) { + objectList << var.value(); + } + + publisher.registerObjects(objects); + publisher.d->initializeClients(); + + QBENCHMARK { + foreach (BenchObject *obj, objectList) { + obj->change(); + } + + publisher.d->clientIsIdle = true; + publisher.d->sendPendingPropertyUpdates(); + } +} + +void TestWebChannel::benchRegisterObjects() +{ + QWebChannel channel; + QSignalSpy initSpy(&channel, SIGNAL(initialized())); + QVERIFY(initSpy.wait()); + + QMetaObjectPublisher publisher; + publisher.setWebChannel(&channel); + + QObject parent; + const QVariantMap objects = createObjects(&parent); + + QBENCHMARK { + publisher.registerObjects(objects); + } +} + QTEST_MAIN(TestWebChannel) diff --git a/tests/webchannel/tst_webchannel.h b/tests/webchannel/tst_webchannel.h index 5ea7a45..173921b 100644 --- a/tests/webchannel/tst_webchannel.h +++ b/tests/webchannel/tst_webchannel.h @@ -92,6 +92,98 @@ private slots: void slot4() {} }; +class BenchObject : public QObject +{ + Q_OBJECT + + Q_PROPERTY(int p0 MEMBER m_p0 NOTIFY p0Changed) + Q_PROPERTY(int p1 MEMBER m_p1 NOTIFY p1Changed) + Q_PROPERTY(int p2 MEMBER m_p2 NOTIFY p2Changed) + Q_PROPERTY(int p3 MEMBER m_p3 NOTIFY p3Changed) + Q_PROPERTY(int p4 MEMBER m_p4 NOTIFY p4Changed) + Q_PROPERTY(int p5 MEMBER m_p5 NOTIFY p5Changed) + Q_PROPERTY(int p6 MEMBER m_p6 NOTIFY p6Changed) + Q_PROPERTY(int p7 MEMBER m_p7 NOTIFY p7Changed) + Q_PROPERTY(int p8 MEMBER m_p8 NOTIFY p8Changed) + Q_PROPERTY(int p9 MEMBER m_p9 NOTIFY p9Changed) +public: + explicit BenchObject(QObject *parent = 0) + : QObject(parent) + , m_p0(0) + , m_p1(0) + , m_p2(0) + , m_p3(0) + , m_p4(0) + , m_p5(0) + , m_p6(0) + , m_p7(0) + , m_p8(0) + , m_p9(0) + { } + + void change() + { + m_p0++; + m_p1++; + m_p2++; + m_p3++; + m_p4++; + m_p5++; + m_p6++; + m_p7++; + m_p8++; + m_p9++; + emit p0Changed(m_p0); + emit p1Changed(m_p1); + emit p2Changed(m_p2); + emit p3Changed(m_p3); + emit p4Changed(m_p4); + emit p5Changed(m_p5); + emit p6Changed(m_p6); + emit p7Changed(m_p7); + emit p8Changed(m_p8); + emit p9Changed(m_p9); + } + +signals: + void s0(); + void s1(); + void s2(); + void s3(); + void s4(); + void s5(); + void s6(); + void s7(); + void s8(); + void s9(); + + void p0Changed(int); + void p1Changed(int); + void p2Changed(int); + void p3Changed(int); + void p4Changed(int); + void p5Changed(int); + void p6Changed(int); + void p7Changed(int); + void p8Changed(int); + void p9Changed(int); + +public slots: + void m0(){}; + void m1(){}; + void m2(){}; + void m3(){}; + void m4(){}; + void m5(){}; + void m6(){}; + void m7(){}; + void m8(){}; + void m9(){}; + +private: + int m_p0, m_p1, m_p2, m_p3, m_p4, m_p5, m_p6, m_p7, m_p8, m_p9; +}; + class TestWebChannel : public QObject { Q_OBJECT @@ -104,6 +196,11 @@ private slots: void testInitChannel(); void testRegisterObjects(); void testInfoForObject(); + + void benchClassInfo(); + void benchInitializeClients(); + void benchPropertyUpdates(); + void benchRegisterObjects(); }; #endif // TST_WEBCHANNEL_H -- cgit v1.2.1