summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiikka Heikkinen <miikka.heikkinen@digia.com>2009-12-16 11:21:44 (GMT)
committerMiikka Heikkinen <miikka.heikkinen@digia.com>2009-12-16 14:06:09 (GMT)
commit06034e9ab2560e777f457fedc8a8cf4380461fed (patch)
treec0ce49e6db9e5f8f9e67f0c1f4db380884b95558
parent4b815774358c3c981dc8bbbcb0dd68abe2e812f2 (diff)
downloadQt-06034e9ab2560e777f457fedc8a8cf4380461fed.zip
Qt-06034e9ab2560e777f457fedc8a8cf4380461fed.tar.gz
Qt-06034e9ab2560e777f457fedc8a8cf4380461fed.tar.bz2
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
-rw-r--r--tests/benchmarks/events/main.cpp15
1 files 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<bool>("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 );
}