summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/qvariant/tst_qvariant.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/qvariant/tst_qvariant.cpp')
-rw-r--r--tests/benchmarks/qvariant/tst_qvariant.cpp115
1 files changed, 50 insertions, 65 deletions
diff --git a/tests/benchmarks/qvariant/tst_qvariant.cpp b/tests/benchmarks/qvariant/tst_qvariant.cpp
index 4a7ad02..0eb1ae2 100644
--- a/tests/benchmarks/qvariant/tst_qvariant.cpp
+++ b/tests/benchmarks/qvariant/tst_qvariant.cpp
@@ -38,7 +38,9 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
#include <QtCore>
+#include <QtGui/QPixmap>
#include <qtest.h>
#define ITERATION_COUNT 1e5
@@ -47,64 +49,73 @@ class tst_qvariant : public QObject
{
Q_OBJECT
private slots:
+ void testBound();
+
void doubleVariantCreation();
void floatVariantCreation();
void rectVariantCreation();
void stringVariantCreation();
+ void pixmapVariantCreation();
+
void doubleVariantSetValue();
void floatVariantSetValue();
void rectVariantSetValue();
void stringVariantSetValue();
+
void doubleVariantAssignment();
void floatVariantAssignment();
void rectVariantAssignment();
void stringVariantAssignment();
};
-
-void tst_qvariant::doubleVariantCreation()
+void tst_qvariant::testBound()
{
- double d = 0;
+ qreal d = qreal(.5);
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(d);
+ d = qBound<qreal>(0, d, 1);
}
}
}
-void tst_qvariant::floatVariantCreation()
+template <typename T>
+static void variantCreation(T val)
{
- float f = 0;
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(f);
+ QVariant v(val);
}
}
}
+void tst_qvariant::doubleVariantCreation()
+{
+ variantCreation<double>(0.0);
+}
+
+void tst_qvariant::floatVariantCreation()
+{
+ variantCreation<float>(0.0f);
+}
+
void tst_qvariant::rectVariantCreation()
{
- QRect r(1,2,3,4);
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(r);
- }
- }
+ variantCreation<QRect>(QRect(1, 2, 3, 4));
}
void tst_qvariant::stringVariantCreation()
{
- QString s;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- QVariant v(s);
- }
- }
+ variantCreation<QString>(QString());
}
-void tst_qvariant::doubleVariantSetValue()
+void tst_qvariant::pixmapVariantCreation()
+{
+ variantCreation<QPixmap>(QPixmap());
+}
+
+template <typename T>
+static void variantSetValue(T d)
{
- double d = 0;
QVariant v;
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
@@ -113,42 +124,29 @@ void tst_qvariant::doubleVariantSetValue()
}
}
+void tst_qvariant::doubleVariantSetValue()
+{
+ variantSetValue<double>(0.0);
+}
+
void tst_qvariant::floatVariantSetValue()
{
- float f = 0;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- qVariantSetValue(v, f);
- }
- }
+ variantSetValue<float>(0.0f);
}
void tst_qvariant::rectVariantSetValue()
{
- QRect r;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- qVariantSetValue(v, r);
- }
- }
+ variantSetValue<QRect>(QRect());
}
void tst_qvariant::stringVariantSetValue()
{
- QString s;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- qVariantSetValue(v, s);
- }
- }
+ variantSetValue<QString>(QString());
}
-void tst_qvariant::doubleVariantAssignment()
+template <typename T>
+static void variantAssignment(T d)
{
- double d = 0;
QVariant v;
QBENCHMARK {
for(int i = 0; i < ITERATION_COUNT; ++i) {
@@ -157,37 +155,24 @@ void tst_qvariant::doubleVariantAssignment()
}
}
+void tst_qvariant::doubleVariantAssignment()
+{
+ variantAssignment<double>(0.0);
+}
+
void tst_qvariant::floatVariantAssignment()
{
- float f = 0;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- v = f;
- }
- }
+ variantAssignment<float>(0.0f);
}
void tst_qvariant::rectVariantAssignment()
{
- QRect r;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- v = r;
- }
- }
+ variantAssignment<QRect>(QRect());
}
void tst_qvariant::stringVariantAssignment()
{
- QString s;
- QVariant v;
- QBENCHMARK {
- for(int i = 0; i < ITERATION_COUNT; ++i) {
- v = s;
- }
- }
+ variantAssignment<QString>(QString());
}
QTEST_MAIN(tst_qvariant)