From 38be0d13830efd2d98281c645c3a60afe05ffece Mon Sep 17 00:00:00 2001 From: Qt by Nokia Date: Wed, 27 Apr 2011 12:05:43 +0200 Subject: Initial import from the monolithic Qt. This is the beginning of revision history for this module. If you want to look at revision history older than this, please refer to the Qt Git wiki for how to use Git history grafting. At the time of writing, this wiki is located here: http://qt.gitorious.org/qt/pages/GitIntroductionWithQt If you have already performed the grafting and you don't see any history beyond this commit, try running "git log" with the "--follow" argument. Branched from the monolithic repo, Qt master branch, at commit 896db169ea224deb96c59ce8af800d019de63f12 --- tests/benchmarks/corelib/kernel/events/events.pro | 8 + tests/benchmarks/corelib/kernel/events/main.cpp | 187 ++++++++++++++ tests/benchmarks/corelib/kernel/kernel.pro | 7 + .../benchmarks/corelib/kernel/qmetaobject/main.cpp | 264 +++++++++++++++++++ .../corelib/kernel/qmetaobject/qmetaobject.pro | 5 + .../corelib/kernel/qmetatype/qmetatype.pro | 7 + .../corelib/kernel/qmetatype/tst_qmetatype.cpp | 285 +++++++++++++++++++++ tests/benchmarks/corelib/kernel/qobject/main.cpp | 185 +++++++++++++ tests/benchmarks/corelib/kernel/qobject/object.cpp | 68 +++++ tests/benchmarks/corelib/kernel/qobject/object.h | 76 ++++++ .../benchmarks/corelib/kernel/qobject/qobject.pro | 9 + .../qtimer_vs_qmetaobject.pro | 12 + .../tst_qtimer_vs_qmetaobject.cpp | 96 +++++++ .../corelib/kernel/qvariant/qvariant.pro | 11 + .../corelib/kernel/qvariant/tst_qvariant.cpp | 272 ++++++++++++++++++++ 15 files changed, 1492 insertions(+) create mode 100644 tests/benchmarks/corelib/kernel/events/events.pro create mode 100644 tests/benchmarks/corelib/kernel/events/main.cpp create mode 100644 tests/benchmarks/corelib/kernel/kernel.pro create mode 100644 tests/benchmarks/corelib/kernel/qmetaobject/main.cpp create mode 100644 tests/benchmarks/corelib/kernel/qmetaobject/qmetaobject.pro create mode 100644 tests/benchmarks/corelib/kernel/qmetatype/qmetatype.pro create mode 100644 tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp create mode 100644 tests/benchmarks/corelib/kernel/qobject/main.cpp create mode 100644 tests/benchmarks/corelib/kernel/qobject/object.cpp create mode 100644 tests/benchmarks/corelib/kernel/qobject/object.h create mode 100644 tests/benchmarks/corelib/kernel/qobject/qobject.pro create mode 100644 tests/benchmarks/corelib/kernel/qtimer_vs_qmetaobject/qtimer_vs_qmetaobject.pro create mode 100644 tests/benchmarks/corelib/kernel/qtimer_vs_qmetaobject/tst_qtimer_vs_qmetaobject.cpp create mode 100644 tests/benchmarks/corelib/kernel/qvariant/qvariant.pro create mode 100644 tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp (limited to 'tests/benchmarks/corelib/kernel') diff --git a/tests/benchmarks/corelib/kernel/events/events.pro b/tests/benchmarks/corelib/kernel/events/events.pro new file mode 100644 index 0000000000..d7d770a944 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/events/events.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_events +DEPENDPATH += . +INCLUDEPATH += . +# Input +SOURCES += main.cpp +QT -= gui diff --git a/tests/benchmarks/corelib/kernel/events/main.cpp b/tests/benchmarks/corelib/kernel/events/main.cpp new file mode 100644 index 0000000000..94dd4b02db --- /dev/null +++ b/tests/benchmarks/corelib/kernel/events/main.cpp @@ -0,0 +1,187 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include + +#include +#include + +class PingPong : public QObject +{ +public: + void setPeer(QObject *peer); + void resetCounter() {m_counter = 100;} + +protected: + bool event(QEvent *e); + +private: + QObject *m_peer; + int m_counter; +}; + +void PingPong::setPeer(QObject *peer) +{ + m_peer = peer; + m_counter = 100; +} + +bool PingPong::event(QEvent *) +{ + --m_counter; + if (m_counter > 0) { + QEvent *e = new QEvent(QEvent::User); + QCoreApplication::postEvent(m_peer, e); + } else { + QTestEventLoop::instance().exitLoop(); + } + return true; +} + +class EventTester : public QObject +{ +public: + int foo(int bar); + +protected: + bool event(QEvent *e); +}; + +bool EventTester::event(QEvent *e) +{ + if (e->type() == QEvent::User+1) + return foo(e->type()) != 0; + return false; +} + +int EventTester::foo(int bar) +{ + return bar + 1; +} + +class EventsBench : public QObject +{ + Q_OBJECT + +private slots: + void initTestCase(); + void cleanupTestCase(); + + void noEvent(); + void sendEvent_data(); + void sendEvent(); + void postEvent_data(); + void postEvent(); +}; + +void EventsBench::initTestCase() +{ +} + +void EventsBench::cleanupTestCase() +{ +} + +void EventsBench::noEvent() +{ + EventTester tst; + int val = 0; + QBENCHMARK { + val += tst.foo(1); + } +} + +void EventsBench::sendEvent_data() +{ + QTest::addColumn("filterEvents"); + QTest::newRow("no eventfilter") << false; + QTest::newRow("eventfilter") << true; +} + +void EventsBench::sendEvent() +{ + QFETCH(bool, filterEvents); + EventTester tst; + if (filterEvents) + tst.installEventFilter(this); + QEvent evt(QEvent::Type(QEvent::User+1)); + QBENCHMARK { + QCoreApplication::sendEvent(&tst, &evt); + } +} + +void EventsBench::postEvent_data() +{ + QTest::addColumn("filterEvents"); + // The first time an eventloop is executed, the case runs radically slower at least + // on some platforms, so test the "no eventfilter" case to get a comparable results + // with the "eventfilter" case. + QTest::newRow("first time, no eventfilter") << false; + QTest::newRow("no eventfilter") << false; + QTest::newRow("eventfilter") << true; +} + +void EventsBench::postEvent() +{ + QFETCH(bool, filterEvents); + PingPong ping; + PingPong pong; + ping.setPeer(&pong); + pong.setPeer(&ping); + if (filterEvents) { + ping.installEventFilter(this); + pong.installEventFilter(this); + } + + QBENCHMARK { + // In case multiple iterations are done, event needs to be created inside the QBENCHMARK, + // or it gets deleted once first iteration exits and can cause a crash. Similarly, + // ping and pong need their counters reset. + QEvent *e = new QEvent(QEvent::User); + ping.resetCounter(); + pong.resetCounter(); + QCoreApplication::postEvent(&ping, e); + QTestEventLoop::instance().enterLoop( 61 ); + } +} + +QTEST_MAIN(EventsBench) + +#include "main.moc" diff --git a/tests/benchmarks/corelib/kernel/kernel.pro b/tests/benchmarks/corelib/kernel/kernel.pro new file mode 100644 index 0000000000..da3f0d609f --- /dev/null +++ b/tests/benchmarks/corelib/kernel/kernel.pro @@ -0,0 +1,7 @@ +TEMPLATE = subdirs +SUBDIRS = \ + events \ + qmetaobject \ + qmetatype \ + qobject \ + qvariant diff --git a/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp b/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp new file mode 100644 index 0000000000..257915e28d --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qmetaobject/main.cpp @@ -0,0 +1,264 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include + +class LotsOfSignals : public QObject +{ + Q_OBJECT +public: + LotsOfSignals() {} + +signals: + void extraSignal1(); + void extraSignal2(); + void extraSignal3(); + void extraSignal4(); + void extraSignal5(); + void extraSignal6(); + void extraSignal7(); + void extraSignal8(); + void extraSignal9(); + void extraSignal10(); + void extraSignal12(); + void extraSignal13(); + void extraSignal14(); + void extraSignal15(); + void extraSignal16(); + void extraSignal17(); + void extraSignal18(); + void extraSignal19(); + void extraSignal20(); + void extraSignal21(); + void extraSignal22(); + void extraSignal23(); + void extraSignal24(); + void extraSignal25(); + void extraSignal26(); + void extraSignal27(); + void extraSignal28(); + void extraSignal29(); + void extraSignal30(); + void extraSignal31(); + void extraSignal32(); + void extraSignal33(); + void extraSignal34(); + void extraSignal35(); + void extraSignal36(); + void extraSignal37(); + void extraSignal38(); + void extraSignal39(); + void extraSignal40(); + void extraSignal41(); + void extraSignal42(); + void extraSignal43(); + void extraSignal44(); + void extraSignal45(); + void extraSignal46(); + void extraSignal47(); + void extraSignal48(); + void extraSignal49(); + void extraSignal50(); + void extraSignal51(); + void extraSignal52(); + void extraSignal53(); + void extraSignal54(); + void extraSignal55(); + void extraSignal56(); + void extraSignal57(); + void extraSignal58(); + void extraSignal59(); + void extraSignal60(); + void extraSignal61(); + void extraSignal62(); + void extraSignal63(); + void extraSignal64(); + void extraSignal65(); + void extraSignal66(); + void extraSignal67(); + void extraSignal68(); + void extraSignal69(); + void extraSignal70(); +}; + +class tst_qmetaobject: public QObject +{ +Q_OBJECT +private slots: + void initTestCase(); + void cleanupTestCase(); + + void indexOfProperty_data(); + void indexOfProperty(); + void indexOfMethod_data(); + void indexOfMethod(); + void indexOfSignal_data(); + void indexOfSignal(); + void indexOfSlot_data(); + void indexOfSlot(); + + void unconnected_data(); + void unconnected(); +}; + +void tst_qmetaobject::initTestCase() +{ +} + +void tst_qmetaobject::cleanupTestCase() +{ +} + +void tst_qmetaobject::indexOfProperty_data() +{ + QTest::addColumn("name"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->propertyCount(); ++i) { + QMetaProperty prop = mo->property(i); + QTest::newRow(prop.name()) << QByteArray(prop.name()); + } +} + +void tst_qmetaobject::indexOfProperty() +{ + QFETCH(QByteArray, name); + const char *p = name.constData(); + const QMetaObject *mo = &QTreeView::staticMetaObject; + QBENCHMARK { + (void)mo->indexOfProperty(p); + } +} + +void tst_qmetaobject::indexOfMethod_data() +{ + QTest::addColumn("method"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->methodCount(); ++i) { + QMetaMethod method = mo->method(i); + QByteArray sig = method.signature(); + QTest::newRow(sig) << sig; + } +} + +void tst_qmetaobject::indexOfMethod() +{ + QFETCH(QByteArray, method); + const char *p = method.constData(); + const QMetaObject *mo = &QTreeView::staticMetaObject; + QBENCHMARK { + (void)mo->indexOfMethod(p); + } +} + +void tst_qmetaobject::indexOfSignal_data() +{ + QTest::addColumn("signal"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->methodCount(); ++i) { + QMetaMethod method = mo->method(i); + if (method.methodType() != QMetaMethod::Signal) + continue; + QByteArray sig = method.signature(); + QTest::newRow(sig) << sig; + } +} + +void tst_qmetaobject::indexOfSignal() +{ + QFETCH(QByteArray, signal); + const char *p = signal.constData(); + const QMetaObject *mo = &QTreeView::staticMetaObject; + QBENCHMARK { + (void)mo->indexOfSignal(p); + } +} + +void tst_qmetaobject::indexOfSlot_data() +{ + QTest::addColumn("slot"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->methodCount(); ++i) { + QMetaMethod method = mo->method(i); + if (method.methodType() != QMetaMethod::Slot) + continue; + QByteArray sig = method.signature(); + QTest::newRow(sig) << sig; + } +} + +void tst_qmetaobject::indexOfSlot() +{ + QFETCH(QByteArray, slot); + const char *p = slot.constData(); + const QMetaObject *mo = &QTreeView::staticMetaObject; + QBENCHMARK { + (void)mo->indexOfSlot(p); + } +} + +void tst_qmetaobject::unconnected_data() +{ + QTest::addColumn("signal_index"); + QTest::newRow("signal--9") << 9; + QTest::newRow("signal--32") << 32; + QTest::newRow("signal--33") << 33; + QTest::newRow("signal--64") << 64; + QTest::newRow("signal--65") << 65; + QTest::newRow("signal--70") << 70; +} + +void tst_qmetaobject::unconnected() +{ + LotsOfSignals *obj = new LotsOfSignals; + QFETCH(int, signal_index); + QVERIFY(obj->metaObject()->methodCount() == 73); + void *v; + QBENCHMARK { + //+1 because QObject has one slot + QMetaObject::metacall(obj, QMetaObject::InvokeMetaMethod, signal_index+1, &v); + } + delete obj; +} + +QTEST_MAIN(tst_qmetaobject) + +#include "main.moc" diff --git a/tests/benchmarks/corelib/kernel/qmetaobject/qmetaobject.pro b/tests/benchmarks/corelib/kernel/qmetaobject/qmetaobject.pro new file mode 100644 index 0000000000..a02273f7d0 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qmetaobject/qmetaobject.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_qmetaobject + +SOURCES += main.cpp diff --git a/tests/benchmarks/corelib/kernel/qmetatype/qmetatype.pro b/tests/benchmarks/corelib/kernel/qmetatype/qmetatype.pro new file mode 100644 index 0000000000..80f9a2a398 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qmetatype/qmetatype.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +QT = core +TEMPLATE = app +TARGET = tst_qmetatype + +SOURCES += tst_qmetatype.cpp + diff --git a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp new file mode 100644 index 0000000000..4ead826d25 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp @@ -0,0 +1,285 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +//TESTED_FILES= + +class tst_QMetaType : public QObject +{ + Q_OBJECT + +public: + tst_QMetaType(); + virtual ~tst_QMetaType(); + +private slots: + void typeBuiltin_data(); + void typeBuiltin(); + void typeBuiltinNotNormalized_data(); + void typeBuiltinNotNormalized(); + void typeCustom(); + void typeCustomNotNormalized(); + void typeNotRegistered(); + void typeNotRegisteredNotNormalized(); + + void typeNameBuiltin_data(); + void typeNameBuiltin(); + void typeNameCustom(); + void typeNameNotRegistered(); + + void isRegisteredBuiltin_data(); + void isRegisteredBuiltin(); + void isRegisteredCustom(); + void isRegisteredNotRegistered(); + + void constructCoreType_data(); + void constructCoreType(); + void constructCoreTypeCopy_data(); + void constructCoreTypeCopy(); +}; + +tst_QMetaType::tst_QMetaType() +{ +} + +tst_QMetaType::~tst_QMetaType() +{ +} + +void tst_QMetaType::typeBuiltin_data() +{ + QTest::addColumn("typeName"); + for (int i = 0; i < QMetaType::User; ++i) { + const char *name = QMetaType::typeName(i); + if (name) + QTest::newRow(name) << QByteArray(name); + } +} + +void tst_QMetaType::typeBuiltin() +{ + QFETCH(QByteArray, typeName); + const char *nm = typeName.constData(); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + QMetaType::type(nm); + } +} + +void tst_QMetaType::typeBuiltinNotNormalized_data() +{ + QTest::addColumn("typeName"); + for (int i = 0; i < QMetaType::User; ++i) { + const char *name = QMetaType::typeName(i); + if (name) + QTest::newRow(name) << QByteArray(name).append(" "); + } +} + +void tst_QMetaType::typeBuiltinNotNormalized() +{ + QFETCH(QByteArray, typeName); + const char *nm = typeName.constData(); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + QMetaType::type(nm); + } +} + +struct Foo { int i; }; + +void tst_QMetaType::typeCustom() +{ + qRegisterMetaType("Foo"); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + QMetaType::type("Foo"); + } +} + +void tst_QMetaType::typeCustomNotNormalized() +{ + qRegisterMetaType("Foo"); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + QMetaType::type("Foo "); + } +} + +void tst_QMetaType::typeNotRegistered() +{ + Q_ASSERT(QMetaType::type("Bar") == 0); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + QMetaType::type("Bar"); + } +} + +void tst_QMetaType::typeNotRegisteredNotNormalized() +{ + Q_ASSERT(QMetaType::type("Bar") == 0); + QBENCHMARK { + for (int i = 0; i < 10000; ++i) + QMetaType::type("Bar "); + } +} + +void tst_QMetaType::typeNameBuiltin_data() +{ + QTest::addColumn("type"); + for (int i = 0; i < QMetaType::User; ++i) { + const char *name = QMetaType::typeName(i); + if (name) + QTest::newRow(name) << i; + } +} + +void tst_QMetaType::typeNameBuiltin() +{ + QFETCH(int, type); + QBENCHMARK { + for (int i = 0; i < 500000; ++i) + QMetaType::typeName(type); + } +} + +void tst_QMetaType::typeNameCustom() +{ + int type = qRegisterMetaType("Foo"); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + QMetaType::typeName(type); + } +} + +void tst_QMetaType::typeNameNotRegistered() +{ + // We don't care much about this case, but test it anyway. + Q_ASSERT(QMetaType::typeName(-1) == 0); + QBENCHMARK { + for (int i = 0; i < 500000; ++i) + QMetaType::typeName(-1); + } +} + +void tst_QMetaType::isRegisteredBuiltin_data() +{ + typeNameBuiltin_data(); +} + +void tst_QMetaType::isRegisteredBuiltin() +{ + QFETCH(int, type); + QBENCHMARK { + for (int i = 0; i < 500000; ++i) + QMetaType::isRegistered(type); + } +} + +void tst_QMetaType::isRegisteredCustom() +{ + int type = qRegisterMetaType("Foo"); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + QMetaType::isRegistered(type); + } +} + +void tst_QMetaType::isRegisteredNotRegistered() +{ + Q_ASSERT(QMetaType::typeName(-1) == 0); + QBENCHMARK { + for (int i = 0; i < 100000; ++i) + QMetaType::isRegistered(-1); + } +} + +void tst_QMetaType::constructCoreType_data() +{ + QTest::addColumn("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" diff --git a/tests/benchmarks/corelib/kernel/qobject/main.cpp b/tests/benchmarks/corelib/kernel/qobject/main.cpp new file mode 100644 index 0000000000..801e368912 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qobject/main.cpp @@ -0,0 +1,185 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include +#include +#include "object.h" +#include +#include + +enum { + CreationDeletionBenckmarkConstant = 34567, + SignalsAndSlotsBenchmarkConstant = 456789 +}; + +class QObjectBenchmark : public QObject +{ +Q_OBJECT +private slots: + void signal_slot_benchmark(); + void signal_slot_benchmark_data(); + void qproperty_benchmark_data(); + void qproperty_benchmark(); + void dynamic_property_benchmark(); + void connect_disconnect_benchmark_data(); + void connect_disconnect_benchmark(); +}; + +void QObjectBenchmark::signal_slot_benchmark_data() +{ + QTest::addColumn("type"); + QTest::newRow("simple function") << 0; + QTest::newRow("single signal/slot") << 1; + QTest::newRow("multi signal/slot") << 2; + QTest::newRow("unconnected signal") << 3; +} + +void QObjectBenchmark::signal_slot_benchmark() +{ + QFETCH(int, type); + + Object singleObject; + Object multiObject; + singleObject.setObjectName("single"); + multiObject.setObjectName("multi"); + + singleObject.connect(&singleObject, SIGNAL(signal0()), SLOT(slot0())); + + multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(slot0())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal1())); + multiObject.connect(&multiObject, SIGNAL(signal1()), SLOT(slot1())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal2())); + multiObject.connect(&multiObject, SIGNAL(signal2()), SLOT(slot2())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal3())); + multiObject.connect(&multiObject, SIGNAL(signal3()), SLOT(slot3())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal4())); + multiObject.connect(&multiObject, SIGNAL(signal4()), SLOT(slot4())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal5())); + multiObject.connect(&multiObject, SIGNAL(signal5()), SLOT(slot5())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal6())); + multiObject.connect(&multiObject, SIGNAL(signal6()), SLOT(slot6())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal7())); + multiObject.connect(&multiObject, SIGNAL(signal7()), SLOT(slot7())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal8())); + multiObject.connect(&multiObject, SIGNAL(signal8()), SLOT(slot8())); + // multiObject.connect(&multiObject, SIGNAL(signal0()), SLOT(signal9())); + multiObject.connect(&multiObject, SIGNAL(signal9()), SLOT(slot9())); + + if (type == 0) { + QBENCHMARK { + singleObject.slot0(); + } + } else if (type == 1) { + QBENCHMARK { + singleObject.emitSignal0(); + } + } else if (type == 2) { + QBENCHMARK { + multiObject.emitSignal0(); + } + } else if (type == 3) { + QBENCHMARK { + singleObject.emitSignal1(); + } + } +} + +void QObjectBenchmark::qproperty_benchmark_data() +{ + QTest::addColumn("name"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->propertyCount(); ++i) { + QMetaProperty prop = mo->property(i); + QTest::newRow(prop.name()) << QByteArray(prop.name()); + } +} + +void QObjectBenchmark::qproperty_benchmark() +{ + QFETCH(QByteArray, name); + const char *p = name.constData(); + QTreeView obj; + QVariant v = obj.property(p); + QBENCHMARK { + obj.setProperty(p, v); + (void)obj.property(p); + } +} + +void QObjectBenchmark::dynamic_property_benchmark() +{ + QTreeView obj; + QBENCHMARK { + obj.setProperty("myProperty", 123); + (void)obj.property("myProperty"); + obj.setProperty("myOtherProperty", 123); + (void)obj.property("myOtherProperty"); + } +} + +void QObjectBenchmark::connect_disconnect_benchmark_data() +{ + QTest::addColumn("signal"); + const QMetaObject *mo = &QTreeView::staticMetaObject; + for (int i = 0; i < mo->methodCount(); ++i) { + QMetaMethod method = mo->method(i); + if (method.methodType() != QMetaMethod::Signal) + continue; + QByteArray sig = method.signature(); + QTest::newRow(sig) << sig; + } +} + +void QObjectBenchmark::connect_disconnect_benchmark() +{ + QFETCH(QByteArray, signal); + signal.prepend('2'); + const char *p = signal.constData(); + QTreeView obj; + QBENCHMARK { + QObject::connect(&obj, p, &obj, p); + QObject::disconnect(&obj, p, &obj, p); + } +} + +QTEST_MAIN(QObjectBenchmark) + +#include "main.moc" diff --git a/tests/benchmarks/corelib/kernel/qobject/object.cpp b/tests/benchmarks/corelib/kernel/qobject/object.cpp new file mode 100644 index 0000000000..67ed322217 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qobject/object.cpp @@ -0,0 +1,68 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include "object.h" + +void Object::emitSignal0() +{ emit signal0(); } +void Object::emitSignal1() +{ emit signal1(); } + + +void Object::slot0() +{ } +void Object::slot1() +{ } +void Object::slot2() +{ } +void Object::slot3() +{ } +void Object::slot4() +{ } +void Object::slot5() +{ } +void Object::slot6() +{ } +void Object::slot7() +{ } +void Object::slot8() +{ } +void Object::slot9() +{ } diff --git a/tests/benchmarks/corelib/kernel/qobject/object.h b/tests/benchmarks/corelib/kernel/qobject/object.h new file mode 100644 index 0000000000..820e4b77d1 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qobject/object.h @@ -0,0 +1,76 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ +#ifndef OBJECT_H +#define OBJECT_H + +#include + +class Object : public QObject +{ + Q_OBJECT +public: + void emitSignal0(); + void emitSignal1(); +signals: + void signal0(); + void signal1(); + void signal2(); + void signal3(); + void signal4(); + void signal5(); + void signal6(); + void signal7(); + void signal8(); + void signal9(); +public slots: + void slot0(); + void slot1(); + void slot2(); + void slot3(); + void slot4(); + void slot5(); + void slot6(); + void slot7(); + void slot8(); + void slot9(); +}; + +#endif // OBJECT_H diff --git a/tests/benchmarks/corelib/kernel/qobject/qobject.pro b/tests/benchmarks/corelib/kernel/qobject/qobject.pro new file mode 100644 index 0000000000..1baaf58b7b --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qobject/qobject.pro @@ -0,0 +1,9 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_qobject +DEPENDPATH += . +INCLUDEPATH += . + +# Input +HEADERS += object.h +SOURCES += main.cpp object.cpp diff --git a/tests/benchmarks/corelib/kernel/qtimer_vs_qmetaobject/qtimer_vs_qmetaobject.pro b/tests/benchmarks/corelib/kernel/qtimer_vs_qmetaobject/qtimer_vs_qmetaobject.pro new file mode 100644 index 0000000000..5ecb94c0f6 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qtimer_vs_qmetaobject/qtimer_vs_qmetaobject.pro @@ -0,0 +1,12 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = qtimer_vs_qmetaobject +DEPENDPATH += . +INCLUDEPATH += . + +CONFIG += release +#CONFIG += debug + + +SOURCES += tst_qtimer_vs_qmetaobject.cpp +QT -= gui diff --git a/tests/benchmarks/corelib/kernel/qtimer_vs_qmetaobject/tst_qtimer_vs_qmetaobject.cpp b/tests/benchmarks/corelib/kernel/qtimer_vs_qmetaobject/tst_qtimer_vs_qmetaobject.cpp new file mode 100644 index 0000000000..0f40dca3b1 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qtimer_vs_qmetaobject/tst_qtimer_vs_qmetaobject.cpp @@ -0,0 +1,96 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include + +#define INVOKE_COUNT 10000 + +class qtimer_vs_qmetaobject : public QObject +{ + Q_OBJECT +private slots: + void testZeroTimerSingleShot(); + void testQueuedInvokeMethod(); +}; + +class InvokeCounter : public QObject { + Q_OBJECT +public: + InvokeCounter() : count(0) { }; +public slots: + void invokeSlot() { + count++; + if (count == INVOKE_COUNT) + QTestEventLoop::instance().exitLoop(); + } +protected: + int count; +}; + +void qtimer_vs_qmetaobject::testZeroTimerSingleShot() +{ + QBENCHMARK { + InvokeCounter invokeCounter; + for(int i = 0; i < INVOKE_COUNT; ++i) { + QTimer::singleShot(0, &invokeCounter, SLOT(invokeSlot())); + } + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + } +} + +void qtimer_vs_qmetaobject::testQueuedInvokeMethod() +{ + QBENCHMARK { + InvokeCounter invokeCounter; + for(int i = 0; i < INVOKE_COUNT; ++i) { + QMetaObject::invokeMethod(&invokeCounter, "invokeSlot", Qt::QueuedConnection); + } + QTestEventLoop::instance().enterLoop(10); + QVERIFY(!QTestEventLoop::instance().timeout()); + } +} + + +QTEST_MAIN(qtimer_vs_qmetaobject) + +#include "tst_qtimer_vs_qmetaobject.moc" diff --git a/tests/benchmarks/corelib/kernel/qvariant/qvariant.pro b/tests/benchmarks/corelib/kernel/qvariant/qvariant.pro new file mode 100644 index 0000000000..f3dd66af44 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qvariant/qvariant.pro @@ -0,0 +1,11 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_bench_qvariant +DEPENDPATH += . +INCLUDEPATH += . + +CONFIG += release +#CONFIG += debug + + +SOURCES += tst_qvariant.cpp diff --git a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp new file mode 100644 index 0000000000..2e217e2a63 --- /dev/null +++ b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp @@ -0,0 +1,272 @@ +/**************************************************************************** +** +** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include + +#define ITERATION_COUNT 1e5 + +class tst_qvariant : public QObject +{ + Q_OBJECT +private slots: + void testBound(); + + void doubleVariantCreation(); + void floatVariantCreation(); + void rectVariantCreation(); + void stringVariantCreation(); + void pixmapVariantCreation(); + + void doubleVariantSetValue(); + void floatVariantSetValue(); + void rectVariantSetValue(); + void stringVariantSetValue(); + + void doubleVariantAssignment(); + void floatVariantAssignment(); + void rectVariantAssignment(); + void stringVariantAssignment(); + + void doubleVariantValue(); + void floatVariantValue(); + void rectVariantValue(); + void stringVariantValue(); + + void createCoreType_data(); + void createCoreType(); + void createCoreTypeCopy_data(); + void createCoreTypeCopy(); +}; + +void tst_qvariant::testBound() +{ + qreal d = qreal(.5); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + d = qBound(0, d, 1); + } + } +} + +template +static void variantCreation(T val) +{ + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + QVariant v(val); + } + } +} + +void tst_qvariant::doubleVariantCreation() +{ + variantCreation(0.0); +} + +void tst_qvariant::floatVariantCreation() +{ + variantCreation(0.0f); +} + +void tst_qvariant::rectVariantCreation() +{ + variantCreation(QRect(1, 2, 3, 4)); +} + +void tst_qvariant::stringVariantCreation() +{ + variantCreation(QString()); +} + +void tst_qvariant::pixmapVariantCreation() +{ + variantCreation(QPixmap()); +} + +template +static void variantSetValue(T d) +{ + QVariant v; + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + qVariantSetValue(v, d); + } + } +} + +void tst_qvariant::doubleVariantSetValue() +{ + variantSetValue(0.0); +} + +void tst_qvariant::floatVariantSetValue() +{ + variantSetValue(0.0f); +} + +void tst_qvariant::rectVariantSetValue() +{ + variantSetValue(QRect()); +} + +void tst_qvariant::stringVariantSetValue() +{ + variantSetValue(QString()); +} + +template +static void variantAssignment(T d) +{ + QVariant v; + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v = d; + } + } +} + +void tst_qvariant::doubleVariantAssignment() +{ + variantAssignment(0.0); +} + +void tst_qvariant::floatVariantAssignment() +{ + variantAssignment(0.0f); +} + +void tst_qvariant::rectVariantAssignment() +{ + variantAssignment(QRect()); +} + +void tst_qvariant::stringVariantAssignment() +{ + variantAssignment(QString()); +} + +void tst_qvariant::doubleVariantValue() +{ + QVariant v(0.0); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v.toDouble(); + } + } +} + +void tst_qvariant::floatVariantValue() +{ + QVariant v(0.0f); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v.toFloat(); + } + } +} + +void tst_qvariant::rectVariantValue() +{ + QVariant v(QRect(1,2,3,4)); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v.toRect(); + } + } +} + +void tst_qvariant::stringVariantValue() +{ + QVariant v = QString(); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + v.toString(); + } + } +} + +void tst_qvariant::createCoreType_data() +{ + QTest::addColumn("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; +} + +// Tests how fast a Qt core type can be default-constructed by a +// QVariant. The purpose of this benchmark is to measure the overhead +// of creating (and destroying) a QVariant compared to creating the +// type directly. +void tst_qvariant::createCoreType() +{ + QFETCH(int, typeId); + QBENCHMARK { + for (int i = 0; i < ITERATION_COUNT; ++i) + QVariant(typeId, (void *)0); + } +} + +void tst_qvariant::createCoreTypeCopy_data() +{ + createCoreType_data(); +} + +// Tests how fast a Qt core type can be copy-constructed by a +// QVariant. The purpose of this benchmark is to measure the overhead +// of creating (and destroying) a QVariant compared to creating the +// type directly. +void tst_qvariant::createCoreTypeCopy() +{ + QFETCH(int, typeId); + QVariant other(typeId, (void *)0); + const void *copy = other.constData(); + QBENCHMARK { + for (int i = 0; i < ITERATION_COUNT; ++i) + QVariant(typeId, copy); + } +} + +QTEST_MAIN(tst_qvariant) + +#include "tst_qvariant.moc" -- cgit v1.2.3