summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/corelib/kernel/qmetatype
diff options
context:
space:
mode:
authorJędrzej Nowacki <jedrzej.nowacki@nokia.com>2011-12-20 17:11:46 +0100
committerQt by Nokia <qt-info@nokia.com>2012-02-16 02:00:15 +0100
commit214e031d56714ba69ef929f1e763e243b393e460 (patch)
tree4732bd79e015eecb85e66ba3a3facc58d5fba9ae /tests/benchmarks/corelib/kernel/qmetatype
parentb9eb3715f55378802a1a0ae2f61d799ab84ee49a (diff)
Implement new static less API for QMetaType.
Currently QMetaType API contains almost only static methods. This works nice until someone needs more information or needs to do more operations on a type. In this case every function call has to do type dispatch. This API allows to avoid redundant type dispatching, by caching a type information in a QMetaType instance. It gives significant performance boost especially for custom types (up to 9x). Change-Id: I223d066268402e072e41ca1d0a3e7bc160655d7f Reviewed-by: Stephen Kelly <stephen.kelly@kdab.com> Reviewed-by: Bradley T. Hughes <bradley.hughes@nokia.com>
Diffstat (limited to 'tests/benchmarks/corelib/kernel/qmetatype')
-rw-r--r--tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp54
1 files changed, 53 insertions, 1 deletions
diff --git a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 1c5dc9227f..a3cdd38e56 100644
--- a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -72,6 +72,8 @@ private slots:
void constructCoreType_data();
void constructCoreType();
+ void constructCoreTypeStaticLess_data();
+ void constructCoreTypeStaticLess();
void constructCoreTypeCopy_data();
void constructCoreTypeCopy();
@@ -79,6 +81,8 @@ private slots:
void constructInPlace();
void constructInPlaceCopy_data();
void constructInPlaceCopy();
+ void constructInPlaceCopyStaticLess_data();
+ void constructInPlaceCopyStaticLess();
};
tst_QMetaType::tst_QMetaType()
@@ -89,6 +93,12 @@ tst_QMetaType::~tst_QMetaType()
{
}
+struct BigClass
+{
+ double n,i,e,r,o,b;
+};
+Q_DECLARE_METATYPE(BigClass);
+
void tst_QMetaType::typeBuiltin_data()
{
QTest::addColumn<QByteArray>("typeName");
@@ -260,6 +270,23 @@ void tst_QMetaType::constructCoreType()
}
}
+void tst_QMetaType::constructCoreTypeStaticLess_data()
+{
+ constructCoreType_data();
+}
+
+void tst_QMetaType::constructCoreTypeStaticLess()
+{
+ QFETCH(int, typeId);
+ QBENCHMARK {
+ QMetaType type(typeId);
+ for (int i = 0; i < 100000; ++i) {
+ void *data = type.create((void *)0);
+ type.destroy(data);
+ }
+ }
+}
+
void tst_QMetaType::constructCoreTypeCopy_data()
{
constructCoreType_data();
@@ -285,6 +312,7 @@ void tst_QMetaType::constructCoreTypeCopy()
void tst_QMetaType::constructInPlace_data()
{
constructCoreType_data();
+ QTest::newRow("custom") << qMetaTypeId<BigClass>();
}
void tst_QMetaType::constructInPlace()
@@ -305,7 +333,7 @@ void tst_QMetaType::constructInPlace()
void tst_QMetaType::constructInPlaceCopy_data()
{
- constructCoreType_data();
+ constructInPlace_data();
}
void tst_QMetaType::constructInPlaceCopy()
@@ -326,5 +354,29 @@ void tst_QMetaType::constructInPlaceCopy()
qFreeAligned(storage);
}
+void tst_QMetaType::constructInPlaceCopyStaticLess_data()
+{
+ constructInPlaceCopy_data();
+}
+
+void tst_QMetaType::constructInPlaceCopyStaticLess()
+{
+ QFETCH(int, typeId);
+ int size = QMetaType::sizeOf(typeId);
+ void *storage = qMallocAligned(size, 2 * sizeof(qlonglong));
+ void *other = QMetaType::create(typeId);
+ QCOMPARE(QMetaType::construct(typeId, storage, other), storage);
+ QMetaType::destruct(typeId, storage);
+ QBENCHMARK {
+ QMetaType type(typeId);
+ for (int i = 0; i < 100000; ++i) {
+ type.construct(storage, other);
+ type.destruct(storage);
+ }
+ }
+ QMetaType::destroy(typeId, other);
+ qFreeAligned(storage);
+}
+
QTEST_MAIN(tst_QMetaType)
#include "tst_qmetatype.moc"