summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks
diff options
context:
space:
mode:
authorRobin Burchell <robin.burchell@theqtcompany.com>2015-11-03 13:58:19 +0100
committerRobin Burchell <robin.burchell@viroteck.net>2016-07-22 12:47:05 +0000
commit57413ad3f61a02368f84b0cbbc022e4df7adfa95 (patch)
treef0a0a1ec3315e1f0b0cbf57ac6b096c6d9866c41 /tests/benchmarks
parent2152049db0fb1a615dfe46fe6a355abe55a384f3 (diff)
QMetaType: Add a benchmark covering creation of QVariant from an enum
This proved to be quite slow in the past due to QReadWriteLock's implementation being suboptimal (prior to its improvement in 343e5d066a6b5583688e16baec20f20e6d9a24e0). This codepath is exercised quite extensively by QML with enum registrations. Change-Id: I94d1e13933bf005604dc4494e2cb5bc25ef3d387 Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
Diffstat (limited to 'tests/benchmarks')
-rw-r--r--tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp
index 9abb9466df..287afff089 100644
--- a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -37,6 +37,15 @@
class tst_qvariant : public QObject
{
Q_OBJECT
+
+public:
+ enum ABenchmarkEnum {
+ FirstEnumValue,
+ SecondEnumValue,
+ ThirdEnumValue
+ };
+ Q_ENUM(ABenchmarkEnum)
+
private slots:
void testBound();
@@ -50,6 +59,7 @@ private slots:
void stringListVariantCreation();
void bigClassVariantCreation();
void smallClassVariantCreation();
+ void enumVariantCreation();
void doubleVariantSetValue();
void floatVariantSetValue();
@@ -58,6 +68,7 @@ private slots:
void stringListVariantSetValue();
void bigClassVariantSetValue();
void smallClassVariantSetValue();
+ void enumVariantSetValue();
void doubleVariantAssignment();
void floatVariantAssignment();
@@ -136,6 +147,16 @@ void variantCreation<SmallClass>(SmallClass val)
}
}
+template <>
+void variantCreation<tst_qvariant::ABenchmarkEnum>(tst_qvariant::ABenchmarkEnum val)
+{
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i) {
+ QVariant::fromValue(val);
+ }
+ }
+}
+
void tst_qvariant::doubleVariantCreation()
{
@@ -179,6 +200,12 @@ void tst_qvariant::smallClassVariantCreation()
variantCreation<SmallClass>(SmallClass());
}
+void tst_qvariant::enumVariantCreation()
+{
+ variantCreation<ABenchmarkEnum>(FirstEnumValue);
+}
+
+
template <typename T>
static void variantSetValue(T d)
{
@@ -225,6 +252,11 @@ void tst_qvariant::smallClassVariantSetValue()
variantSetValue<SmallClass>(SmallClass());
}
+void tst_qvariant::enumVariantSetValue()
+{
+ variantSetValue<ABenchmarkEnum>(FirstEnumValue);
+}
+
template <typename T>
static void variantAssignment(T d)
{