From 28c3d56d4fe8ccd0af9db5b9c39e297f3aed13be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C4=99drzej=20Nowacki?= Date: Wed, 12 Oct 2011 15:05:44 +0200 Subject: [PATCH] Extend QVariant benchmarks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add new cases for custom types and QStringList. Change-Id: I79f8d415be43774e6b2488e8a6a8028bf4a5fd45 Reviewed-by: João Abecasis --- .../corelib/kernel/qvariant/tst_qvariant.cpp | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp index f1c49c3af5..85d14b99b6 100644 --- a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp +++ b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp @@ -56,16 +56,23 @@ private slots: void rectVariantCreation(); void stringVariantCreation(); void pixmapVariantCreation(); + void stringListVariantCreation(); + void bigClassVariantCreation(); + void smallClassVariantCreation(); void doubleVariantSetValue(); void floatVariantSetValue(); void rectVariantSetValue(); void stringVariantSetValue(); + void stringListVariantSetValue(); + void bigClassVariantSetValue(); + void smallClassVariantSetValue(); void doubleVariantAssignment(); void floatVariantAssignment(); void rectVariantAssignment(); void stringVariantAssignment(); + void stringListVariantAssignment(); void doubleVariantValue(); void floatVariantValue(); @@ -78,6 +85,20 @@ private slots: void createCoreTypeCopy(); }; +struct BigClass +{ + double n,i,e,r,o,b; +}; +Q_STATIC_ASSERT(sizeof(BigClass) > sizeof(QVariant::Private::Data)); +Q_DECLARE_METATYPE(BigClass); + +struct SmallClass +{ + char s; +}; +Q_STATIC_ASSERT(sizeof(SmallClass) <= sizeof(QVariant::Private::Data)); +Q_DECLARE_METATYPE(SmallClass); + void tst_qvariant::testBound() { qreal d = qreal(.5); @@ -98,6 +119,27 @@ static void variantCreation(T val) } } +template <> +void variantCreation(BigClass val) +{ + QBENCHMARK { + for (int i = 0; i < ITERATION_COUNT; ++i) { + QVariant::fromValue(val); + } + } +} + +template <> +void variantCreation(SmallClass val) +{ + QBENCHMARK { + for (int i = 0; i < ITERATION_COUNT; ++i) { + QVariant::fromValue(val); + } + } +} + + void tst_qvariant::doubleVariantCreation() { variantCreation(0.0); @@ -123,6 +165,21 @@ void tst_qvariant::pixmapVariantCreation() variantCreation(QPixmap()); } +void tst_qvariant::stringListVariantCreation() +{ + variantCreation(QStringList()); +} + +void tst_qvariant::bigClassVariantCreation() +{ + variantCreation(BigClass()); +} + +void tst_qvariant::smallClassVariantCreation() +{ + variantCreation(SmallClass()); +} + template static void variantSetValue(T d) { @@ -154,6 +211,21 @@ void tst_qvariant::stringVariantSetValue() variantSetValue(QString()); } +void tst_qvariant::stringListVariantSetValue() +{ + variantSetValue(QStringList()); +} + +void tst_qvariant::bigClassVariantSetValue() +{ + variantSetValue(BigClass()); +} + +void tst_qvariant::smallClassVariantSetValue() +{ + variantSetValue(SmallClass()); +} + template static void variantAssignment(T d) { @@ -185,6 +257,11 @@ void tst_qvariant::stringVariantAssignment() variantAssignment(QString()); } +void tst_qvariant::stringListVariantAssignment() +{ + variantAssignment(QStringList()); +} + void tst_qvariant::doubleVariantValue() { QVariant v(0.0);