Extend QVariant benchmarks

Add new cases for custom types and QStringList.

Change-Id: I79f8d415be43774e6b2488e8a6a8028bf4a5fd45
Reviewed-by: João Abecasis <joao.abecasis@nokia.com>
This commit is contained in:
Jędrzej Nowacki 2011-10-12 15:05:44 +02:00 committed by Qt by Nokia
parent 1d01bc1e83
commit 28c3d56d4f

View File

@ -56,16 +56,23 @@ private slots:
void rectVariantCreation(); void rectVariantCreation();
void stringVariantCreation(); void stringVariantCreation();
void pixmapVariantCreation(); void pixmapVariantCreation();
void stringListVariantCreation();
void bigClassVariantCreation();
void smallClassVariantCreation();
void doubleVariantSetValue(); void doubleVariantSetValue();
void floatVariantSetValue(); void floatVariantSetValue();
void rectVariantSetValue(); void rectVariantSetValue();
void stringVariantSetValue(); void stringVariantSetValue();
void stringListVariantSetValue();
void bigClassVariantSetValue();
void smallClassVariantSetValue();
void doubleVariantAssignment(); void doubleVariantAssignment();
void floatVariantAssignment(); void floatVariantAssignment();
void rectVariantAssignment(); void rectVariantAssignment();
void stringVariantAssignment(); void stringVariantAssignment();
void stringListVariantAssignment();
void doubleVariantValue(); void doubleVariantValue();
void floatVariantValue(); void floatVariantValue();
@ -78,6 +85,20 @@ private slots:
void createCoreTypeCopy(); 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() void tst_qvariant::testBound()
{ {
qreal d = qreal(.5); qreal d = qreal(.5);
@ -98,6 +119,27 @@ static void variantCreation(T val)
} }
} }
template <>
void variantCreation<BigClass>(BigClass val)
{
QBENCHMARK {
for (int i = 0; i < ITERATION_COUNT; ++i) {
QVariant::fromValue(val);
}
}
}
template <>
void variantCreation<SmallClass>(SmallClass val)
{
QBENCHMARK {
for (int i = 0; i < ITERATION_COUNT; ++i) {
QVariant::fromValue(val);
}
}
}
void tst_qvariant::doubleVariantCreation() void tst_qvariant::doubleVariantCreation()
{ {
variantCreation<double>(0.0); variantCreation<double>(0.0);
@ -123,6 +165,21 @@ void tst_qvariant::pixmapVariantCreation()
variantCreation<QPixmap>(QPixmap()); variantCreation<QPixmap>(QPixmap());
} }
void tst_qvariant::stringListVariantCreation()
{
variantCreation<QStringList>(QStringList());
}
void tst_qvariant::bigClassVariantCreation()
{
variantCreation<BigClass>(BigClass());
}
void tst_qvariant::smallClassVariantCreation()
{
variantCreation<SmallClass>(SmallClass());
}
template <typename T> template <typename T>
static void variantSetValue(T d) static void variantSetValue(T d)
{ {
@ -154,6 +211,21 @@ void tst_qvariant::stringVariantSetValue()
variantSetValue<QString>(QString()); variantSetValue<QString>(QString());
} }
void tst_qvariant::stringListVariantSetValue()
{
variantSetValue<QStringList>(QStringList());
}
void tst_qvariant::bigClassVariantSetValue()
{
variantSetValue<BigClass>(BigClass());
}
void tst_qvariant::smallClassVariantSetValue()
{
variantSetValue<SmallClass>(SmallClass());
}
template <typename T> template <typename T>
static void variantAssignment(T d) static void variantAssignment(T d)
{ {
@ -185,6 +257,11 @@ void tst_qvariant::stringVariantAssignment()
variantAssignment<QString>(QString()); variantAssignment<QString>(QString());
} }
void tst_qvariant::stringListVariantAssignment()
{
variantAssignment<QStringList>(QStringList());
}
void tst_qvariant::doubleVariantValue() void tst_qvariant::doubleVariantValue()
{ {
QVariant v(0.0); QVariant v(0.0);