From b0470cd7553d26e73929bf9719eea9f49aeb6824 Mon Sep 17 00:00:00 2001 From: Andreas Aardal Hanssen Date: Wed, 5 Aug 2009 08:16:59 +0200 Subject: Add benchmarks for QGraphicsItem::setParenItem(). Ensure we test simple and deep constructs of setParentItem(). These benchmarks don't cover slowness in ancestor flag updating. QVariant is already identified as a contributor to this slowness, as is updating of the depth value (a deep tree crawl). Reviewed-by: Aaron Kennedy --- tests/benchmarks/qgraphicsitem/qgraphicsitem.pro | 1 - .../benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp | 26 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro b/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro index c8fc07b..726bb96 100644 --- a/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro +++ b/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro @@ -3,4 +3,3 @@ TEMPLATE = app TARGET = tst_qgraphicsitem SOURCES += tst_qgraphicsitem.cpp - diff --git a/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp b/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp index 42f2e6b..62a5b5c 100644 --- a/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp +++ b/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp @@ -25,6 +25,8 @@ public slots: void cleanup(); private slots: + void setParentItem(); + void setParentItem_deep(); void setPos_data(); void setPos(); void setTransform_data(); @@ -52,6 +54,30 @@ void tst_QGraphicsItem::cleanup() { } +void tst_QGraphicsItem::setParentItem() +{ + QBENCHMARK { + QGraphicsRectItem rect; + QGraphicsRectItem *childRect = new QGraphicsRectItem; + childRect->setParentItem(&rect); + } +} + +void tst_QGraphicsItem::setParentItem_deep() +{ + QBENCHMARK { + QGraphicsRectItem rect; + QGraphicsRectItem *lastRect = ▭ + for (int i = 0; i < 10; ++i) { + QGraphicsRectItem *childRect = new QGraphicsRectItem; + childRect->setParentItem(lastRect); + lastRect = childRect; + } + QGraphicsItem *first = rect.children().first(); + first->setParentItem(0); + } +} + void tst_QGraphicsItem::setPos_data() { QTest::addColumn("pos"); -- cgit v0.12