aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Berres <armin.berres@basyskom.de>2010-08-06 13:37:43 +0200
committerMiroslav Safr <miroslav.safr@tieto.com>2010-08-10 11:11:09 +0300
commit2d20d449a765b858560e05abe5e02f9aed39593a (patch)
treedaf26c66e42459494b17977413a6ecd1831f0940
parentbee34346dd4cb360ddd9b0ca21fbb3714782284c (diff)
Changes: introduce MBENCHMARK_ONCE
RevBy: Peter Penz Details: This commit works around <http://bugreports.qt.nokia.com/browse/QTBUG-12689> Ideally the macro would not be needed at all but otherwise we have no way to measure static initialization. The results we were getting so far were pure lies.
-rw-r--r--benchmarks/common/mbenchmark.h21
-rw-r--r--benchmarks/common_top.pri2
-rw-r--r--benchmarks/pt_mapplication/pt_mapplication.cpp10
-rw-r--r--benchmarks/pt_mcomponentdata/pt_mcomponentdata.cpp6
-rw-r--r--benchmarks/pt_minimalmapplication/pt_minimalmapplication.cpp10
-rw-r--r--benchmarks/pt_minimalqtapplication/pt_minimalqtapplication.cpp10
-rw-r--r--benchmarks/pt_mtheme/pt_mtheme.cpp5
-rw-r--r--benchmarks/pt_qapplication/pt_qapplication.cpp11
8 files changed, 58 insertions, 17 deletions
diff --git a/benchmarks/common/mbenchmark.h b/benchmarks/common/mbenchmark.h
new file mode 100644
index 00000000..87a60e6b
--- /dev/null
+++ b/benchmarks/common/mbenchmark.h
@@ -0,0 +1,21 @@
+
+// QBENCHARK_ONCE causes the code to be executed twice
+// only the runtime of the second run is actually measured.
+// measuring the time needed to initialize static data is
+// therefor not possible. to work around this we just execute
+// the real code in the second itereation.
+// this macro is also handy when you allocate memory but do
+// not free it in the test slot. with QBENCHMARK_ONCE you have
+// a memory leak in this case.
+// ATTENTION: make sure the code you want to measure works with
+// this hack
+// See <http://bugreports.qt.nokia.com/browse/QTBUG-12689>
+#define MBENCHMARK_ONCE(CODE) \
+ QBENCHMARK_ONCE { \
+ static bool firstRun = true; \
+ if (firstRun) { \
+ firstRun = false; \
+ } else { \
+ CODE \
+ } \
+ }
diff --git a/benchmarks/common_top.pri b/benchmarks/common_top.pri
index 1ead9fb9..da0916f5 100644
--- a/benchmarks/common_top.pri
+++ b/benchmarks/common_top.pri
@@ -5,7 +5,7 @@ MSRCDIR = $${M_SOURCE_TREE}/src
STUBSDIR = ../stubs
INCLUDEPATH += \
. \
- $$STUBSDIR \
+ ../common \
$$MSRCDIR/include \
$$MSRCDIR/corelib/core \
$$MSRCDIR/corelib/widgets \
diff --git a/benchmarks/pt_mapplication/pt_mapplication.cpp b/benchmarks/pt_mapplication/pt_mapplication.cpp
index 44e9597e..3fcda314 100644
--- a/benchmarks/pt_mapplication/pt_mapplication.cpp
+++ b/benchmarks/pt_mapplication/pt_mapplication.cpp
@@ -21,9 +21,11 @@
#include <QProcess>
#include <qtest.h>
+#include <mbenchmark.h>
#include "pt_mapplication.h"
+
/*
Test how long it takes to launch an application which is quitting immediately.
*/
@@ -40,26 +42,26 @@ void Pt_MApplication::processCreationAndCtor()
void Pt_MApplication::ctor()
{
MApplication *a = NULL;
- QBENCHMARK_ONCE {
+ MBENCHMARK_ONCE(
int fakeArgc = 1;
char *fakeArgv[fakeArgc];
char appName[] = "./pt_mapplication";
fakeArgv[0] = appName;
a = new MApplication(fakeArgc, fakeArgv);
- }
+ )
delete a;
}
void Pt_MApplication::ctor2()
{
MApplication *a = NULL;
- QBENCHMARK_ONCE {
+ MBENCHMARK_ONCE(
int fakeArgc = 1;
char *fakeArgv[fakeArgc];
char appName[] = "./pt_mapplication2";
fakeArgv[0] = appName;
a = new MApplication(fakeArgc, fakeArgv);
- }
+ )
delete a;
}
diff --git a/benchmarks/pt_mcomponentdata/pt_mcomponentdata.cpp b/benchmarks/pt_mcomponentdata/pt_mcomponentdata.cpp
index b8f2705b..0e19972b 100644
--- a/benchmarks/pt_mcomponentdata/pt_mcomponentdata.cpp
+++ b/benchmarks/pt_mcomponentdata/pt_mcomponentdata.cpp
@@ -19,9 +19,11 @@
#include "pt_mcomponentdata.h"
+#include <mbenchmark.h>
#include <MComponentData>
#include <MApplication>
+
void Pt_MComponentData::constructor()
{
int argc = 1;
@@ -30,9 +32,9 @@ void Pt_MComponentData::constructor()
argv[0] = appName;
MComponentData *componentData = 0;
- QBENCHMARK_ONCE {
+ MBENCHMARK_ONCE(
componentData = new MComponentData(argc, argv, appName);
- }
+ )
delete componentData;
}
diff --git a/benchmarks/pt_minimalmapplication/pt_minimalmapplication.cpp b/benchmarks/pt_minimalmapplication/pt_minimalmapplication.cpp
index 8b210c59..49a1136e 100644
--- a/benchmarks/pt_minimalmapplication/pt_minimalmapplication.cpp
+++ b/benchmarks/pt_minimalmapplication/pt_minimalmapplication.cpp
@@ -31,9 +31,15 @@
#include <qtest.h>
#define MY_QBENCHMARK_ONCE(CODE) \
- if (!noBenchmark) \
+ if (!noBenchmark) { \
QBENCHMARK_ONCE { \
- CODE \
+ static bool firstRun = true; \
+ if (!firstRun) { \
+ firstRun = false; \
+ } else { \
+ CODE \
+ } \
+ } \
} else { \
CODE \
}
diff --git a/benchmarks/pt_minimalqtapplication/pt_minimalqtapplication.cpp b/benchmarks/pt_minimalqtapplication/pt_minimalqtapplication.cpp
index a845fda4..1b4c2c27 100644
--- a/benchmarks/pt_minimalqtapplication/pt_minimalqtapplication.cpp
+++ b/benchmarks/pt_minimalqtapplication/pt_minimalqtapplication.cpp
@@ -30,9 +30,15 @@
#include "pt_minimalqtapplication.h"
#define MY_QBENCHMARK_ONCE(CODE) \
- if (!noBenchmark) \
+ if (!noBenchmark) { \
QBENCHMARK_ONCE { \
- CODE \
+ static bool firstRun = true; \
+ if (!firstRun) { \
+ firstRun = false; \
+ } else { \
+ CODE \
+ } \
+ } \
} else { \
CODE \
}
diff --git a/benchmarks/pt_mtheme/pt_mtheme.cpp b/benchmarks/pt_mtheme/pt_mtheme.cpp
index 52f4bf95..596e6273 100644
--- a/benchmarks/pt_mtheme/pt_mtheme.cpp
+++ b/benchmarks/pt_mtheme/pt_mtheme.cpp
@@ -19,6 +19,7 @@
#include "pt_mtheme.h"
+#include <mbenchmark.h>
#include <MComponentData>
#include <MTheme>
@@ -27,9 +28,9 @@
void Pt_MTheme::constructor()
{
MTheme *theme = NULL;
- QBENCHMARK_ONCE {
+ MBENCHMARK_ONCE (
theme = new MTheme("widgetsgallery");
- }
+ )
delete theme;
}
diff --git a/benchmarks/pt_qapplication/pt_qapplication.cpp b/benchmarks/pt_qapplication/pt_qapplication.cpp
index 8d52b560..b281ce1f 100644
--- a/benchmarks/pt_qapplication/pt_qapplication.cpp
+++ b/benchmarks/pt_qapplication/pt_qapplication.cpp
@@ -19,11 +19,14 @@
#include "pt_qapplication.h"
+#include <mbenchmark.h>
+
#include <QApplication>
#include <QProcess>
#include <qtest.h>
+
void Pt_QApplication::processCreation()
{
executeSelf(QLatin1String("--exit-immediately"));
@@ -37,26 +40,26 @@ void Pt_QApplication::processCreationAndCtor()
void Pt_QApplication::ctor()
{
QApplication *a(NULL);
- QBENCHMARK_ONCE {
+ MBENCHMARK_ONCE (
int fakeArgc = 1;
char *fakeArgv[fakeArgc];
char appName[] = "./pt_qapplication";
fakeArgv[0] = appName;
a = new QApplication(fakeArgc, fakeArgv);
- }
+ )
delete a;
}
void Pt_QApplication::ctor2()
{
QApplication *a(NULL);
- QBENCHMARK_ONCE {
+ MBENCHMARK_ONCE (
int fakeArgc = 1;
char *fakeArgv[fakeArgc];
char appName[] = "./pt_qapplication2";
fakeArgv[0] = appName;
a = new QApplication(fakeArgc, fakeArgv);
- }
+ )
delete a;
}