From 06034e9ab2560e777f457fedc8a8cf4380461fed Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Wed, 16 Dec 2009 13:21:44 +0200 Subject: Fixed events benchmark postEvent function The postEvent function was causing problems in Symbian because it couldn't handle multiple iterations of the benchmark. - Moved event allocation inside QBENCHMARK so that each iteration will have a fresh event object. - Added resetting of the PingPong counters inside QBENCHMARK. - Used QTestEventLoop::instance().exitLoop() instead of QCoreApplication::quit() to make the cases beyond first to actually test something meaningful. - Added a "first time" case to postEvent_data, as the first time the event loop is used it takes much longer that the subsequent times, at least in Symbian, so that skewed the results. Task-number: QTBUG-6688 Reviewed-by: axis --- tests/benchmarks/events/main.cpp | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/tests/benchmarks/events/main.cpp b/tests/benchmarks/events/main.cpp index 7c9de8f..09d6c53 100644 --- a/tests/benchmarks/events/main.cpp +++ b/tests/benchmarks/events/main.cpp @@ -47,6 +47,7 @@ class PingPong : public QObject { public: void setPeer(QObject *peer); + void resetCounter() {m_counter = 100;} protected: bool event(QEvent *e); @@ -69,7 +70,7 @@ bool PingPong::event(QEvent *) QEvent *e = new QEvent(QEvent::User); QCoreApplication::postEvent(m_peer, e); } else { - QCoreApplication::quit(); + QTestEventLoop::instance().exitLoop(); } return true; } @@ -149,6 +150,10 @@ void EventsBench::sendEvent() void EventsBench::postEvent_data() { QTest::addColumn("filterEvents"); + // The first time an eventloop is executed, the case runs radically slower at least + // on some platforms, so test the "no eventfilter" case to get a comparable results + // with the "eventfilter" case. + QTest::newRow("first time, no eventfilter") << false; QTest::newRow("no eventfilter") << false; QTest::newRow("eventfilter") << true; } @@ -164,8 +169,14 @@ void EventsBench::postEvent() ping.installEventFilter(this); pong.installEventFilter(this); } - QEvent *e = new QEvent(QEvent::User); + QBENCHMARK { + // In case multiple iterations are done, event needs to be created inside the QBENCHMARK, + // or it gets deleted once first iteration exits and can cause a crash. Similarly, + // ping and pong need their counters reset. + QEvent *e = new QEvent(QEvent::User); + ping.resetCounter(); + pong.resetCounter(); QCoreApplication::postEvent(&ping, e); QTestEventLoop::instance().enterLoop( 61 ); } -- cgit v0.12