diff options
author | Kent Hansen <kent.hansen@nokia.com> | 2010-08-02 14:11:33 (GMT) |
---|---|---|
committer | Kent Hansen <kent.hansen@nokia.com> | 2010-08-05 09:52:44 (GMT) |
commit | a0ee11510df847fee64274d260a6c5f693a70787 (patch) | |
tree | 0c8a043532c79601640fb00de3008652c891e3fd /tests/benchmarks/corelib | |
parent | cda344eaa344e82ac682f9c7979fd5222333cab1 (diff) | |
download | Qt-a0ee11510df847fee64274d260a6c5f693a70787.zip Qt-a0ee11510df847fee64274d260a6c5f693a70787.tar.gz Qt-a0ee11510df847fee64274d260a6c5f693a70787.tar.bz2 |
Add benchmarks for QMetaType::construct(int type, void *copy = 0)
Tests all built-in (core and GUI) types, both default construction
(copy == 0) and copy construction.
The benchmarks for GUI types must go into a separate file because
core tests don't (and shouldn't) link against QtGui.
Reviewed-by: Benjamin Poulain
Diffstat (limited to 'tests/benchmarks/corelib')
-rw-r--r-- | tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp index 36399af..ebeea84 100644 --- a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp +++ b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -71,6 +71,11 @@ private slots: void isRegisteredBuiltin(); void isRegisteredCustom(); void isRegisteredNotRegistered(); + + void constructCoreType_data(); + void constructCoreType(); + void constructCoreTypeCopy_data(); + void constructCoreTypeCopy(); }; tst_QMetaType::tst_QMetaType() @@ -229,5 +234,52 @@ void tst_QMetaType::isRegisteredNotRegistered() } } +void tst_QMetaType::constructCoreType_data() +{ + QTest::addColumn<int>("typeId"); + for (int i = 0; i <= QMetaType::LastCoreType; ++i) + QTest::newRow(QMetaType::typeName(i)) << i; + for (int i = QMetaType::FirstCoreExtType; i <= QMetaType::LastCoreExtType; ++i) + QTest::newRow(QMetaType::typeName(i)) << i; + // GUI types are tested in tst_QGuiMetaType. +} + +// Tests how fast QMetaType can default-construct and destroy a Qt +// core type. The purpose of this benchmark is to measure the overhead +// of using type id-based creation compared to creating the type +// directly (i.e. "T *t = new T(); delete t;"). +void tst_QMetaType::constructCoreType() +{ + QFETCH(int, typeId); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) { + void *data = QMetaType::construct(typeId, (void *)0); + QMetaType::destroy(typeId, data); + } + } +} + +void tst_QMetaType::constructCoreTypeCopy_data() +{ + constructCoreType_data(); +} + +// Tests how fast QMetaType can copy-construct and destroy a Qt core +// type. The purpose of this benchmark is to measure the overhead of +// using type id-based creation compared to creating the type directly +// (i.e. "T *t = new T(other); delete t;"). +void tst_QMetaType::constructCoreTypeCopy() +{ + QFETCH(int, typeId); + QVariant other(typeId, (void *)0); + const void *copy = other.constData(); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) { + void *data = QMetaType::construct(typeId, copy); + QMetaType::destroy(typeId, data); + } + } +} + QTEST_MAIN(tst_QMetaType) #include "tst_qmetatype.moc" |