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>
This commit is contained in:
parent
2152049db0
commit
57413ad3f6
@ -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)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user