diff options
Diffstat (limited to 'tests/benchmarks')
46 files changed, 3934 insertions, 100 deletions
diff --git a/tests/benchmarks/benchmarks.pro b/tests/benchmarks/benchmarks.pro index 8e2c243..bf02731 100644 --- a/tests/benchmarks/benchmarks.pro +++ b/tests/benchmarks/benchmarks.pro @@ -1,13 +1,17 @@ TEMPLATE = subdirs SUBDIRS = containers-associative \ containers-sequential \ + qanimation \ qbytearray \ qpainter \ qtestlib-simple events \ qiodevice \ qpixmap \ blendbench \ - qstringlist \ + qstring \ + qstringlist \ + qmatrix4x4 \ + qnetworkreply \ qobject \ qrect \ qregexp \ diff --git a/tests/benchmarks/qanimation/dummyanimation.cpp b/tests/benchmarks/qanimation/dummyanimation.cpp new file mode 100644 index 0000000..53c42b0 --- /dev/null +++ b/tests/benchmarks/qanimation/dummyanimation.cpp @@ -0,0 +1,61 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "dummyanimation.h" +#include "dummyobject.h" + + +DummyAnimation::DummyAnimation(DummyObject *d) : m_dummy(d) +{ +} + +void DummyAnimation::updateCurrentValue(const QVariant &value) +{ + if (state() == Stopped) + return; + if (m_dummy) + m_dummy->setRect(value.toRect()); +} + +void DummyAnimation::updateState(State state) +{ + Q_UNUSED(state); +} diff --git a/tests/benchmarks/qanimation/dummyanimation.h b/tests/benchmarks/qanimation/dummyanimation.h new file mode 100644 index 0000000..6318a32 --- /dev/null +++ b/tests/benchmarks/qanimation/dummyanimation.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#ifndef _DUMMYANIMATION_H__ + +class DummyObject; + +class DummyAnimation : public QVariantAnimation +{ +public: + DummyAnimation(DummyObject *d); + + void updateCurrentValue(const QVariant &value); + void updateState(State state); + +private: + DummyObject *m_dummy; +}; + +#endif diff --git a/tests/benchmarks/qanimation/dummyobject.cpp b/tests/benchmarks/qanimation/dummyobject.cpp new file mode 100644 index 0000000..10b24e2 --- /dev/null +++ b/tests/benchmarks/qanimation/dummyobject.cpp @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtGui module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "dummyobject.h" + +DummyObject::DummyObject() +{ +} + +QRect DummyObject::rect() const +{ + return m_rect; +} + +void DummyObject::setRect(const QRect &r) +{ + m_rect = r; +} + +float DummyObject::opacity() const +{ + return m_opacity; +} + +void DummyObject::setOpacity(float o) +{ + m_opacity = o; +} diff --git a/tests/benchmarks/qanimation/dummyobject.h b/tests/benchmarks/qanimation/dummyobject.h new file mode 100644 index 0000000..bf5b60c6 --- /dev/null +++ b/tests/benchmarks/qanimation/dummyobject.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#ifndef _DUMMYOBJECT_H__ + +class DummyObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(QRect rect READ rect WRITE setRect) + Q_PROPERTY(float opacity READ opacity WRITE setOpacity) +public: + DummyObject(); + QRect rect() const; + void setRect(const QRect &r); + float opacity() const; + void setOpacity(float); + +private: + QRect m_rect; + float m_opacity; +}; + + +#endif diff --git a/tests/benchmarks/qanimation/main.cpp b/tests/benchmarks/qanimation/main.cpp new file mode 100644 index 0000000..5c9fa41 --- /dev/null +++ b/tests/benchmarks/qanimation/main.cpp @@ -0,0 +1,191 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> +#include <qtest.h> + +#include "dummyobject.h" +#include "dummyanimation.h" +#include "rectanimation.h" + +#define ITERATION_COUNT 10e3 + +class tst_qanimation : public QObject +{ + Q_OBJECT +private slots: + void itemPropertyAnimation(); + void itemPropertyAnimation_data() { data();} + void dummyAnimation(); + void dummyAnimation_data() { data();} + void dummyPropertyAnimation(); + void dummyPropertyAnimation_data() { data();} + void rectAnimation(); + void rectAnimation_data() { data();} + + void floatAnimation_data() { data(); } + void floatAnimation(); + +private: + void data(); +}; + + +void tst_qanimation::data() +{ + QTest::addColumn<bool>("started"); + QTest::newRow("NotRunning") << false; + QTest::newRow("Running") << true; +} + +void tst_qanimation::itemPropertyAnimation() +{ + QFETCH(bool, started); + QGraphicsWidget item; + + //then the property animation + { + QPropertyAnimation anim(&item, "pos"); + anim.setDuration(ITERATION_COUNT); + anim.setStartValue(QPointF(0,0)); + anim.setEndValue(QPointF(ITERATION_COUNT,ITERATION_COUNT)); + if (started) + anim.start(); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + anim.setCurrentTime(i); + } + } + } + +} + +void tst_qanimation::dummyAnimation() +{ + QFETCH(bool, started); + DummyObject dummy; + + //first the dummy animation + { + DummyAnimation anim(&dummy); + anim.setDuration(ITERATION_COUNT); + anim.setStartValue(QRect(0, 0, 0, 0)); + anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT)); + if (started) + anim.start(); + QBENCHMARK { + for(int i = 0; i < anim.duration(); ++i) { + anim.setCurrentTime(i); + } + } + } +} + +void tst_qanimation::dummyPropertyAnimation() +{ + QFETCH(bool, started); + DummyObject dummy; + + //then the property animation + { + QPropertyAnimation anim(&dummy, "rect"); + anim.setDuration(ITERATION_COUNT); + anim.setStartValue(QRect(0, 0, 0, 0)); + anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT)); + if (started) + anim.start(); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + anim.setCurrentTime(i); + } + } + } +} + +void tst_qanimation::rectAnimation() +{ + //this is the simplest animation you can do + QFETCH(bool, started); + DummyObject dummy; + + //then the property animation + { + RectAnimation anim(&dummy); + anim.setDuration(ITERATION_COUNT); + anim.setStartValue(QRect(0, 0, 0, 0)); + anim.setEndValue(QRect(0, 0, ITERATION_COUNT,ITERATION_COUNT)); + if (started) + anim.start(); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + anim.setCurrentTime(i); + } + } + } +} + +void tst_qanimation::floatAnimation() +{ + //this is the simplest animation you can do + QFETCH(bool, started); + DummyObject dummy; + + //then the property animation + { + QPropertyAnimation anim(&dummy, "opacity"); + anim.setDuration(ITERATION_COUNT); + anim.setStartValue(0.f); + anim.setEndValue(1.f); + if (started) + anim.start(); + QBENCHMARK { + for(int i = 0; i < ITERATION_COUNT; ++i) { + anim.setCurrentTime(i); + } + } + } +} + + + +QTEST_MAIN(tst_qanimation) + +#include "main.moc" diff --git a/tests/benchmarks/qanimation/qanimation.pro b/tests/benchmarks/qanimation/qanimation.pro new file mode 100644 index 0000000..55cd75e --- /dev/null +++ b/tests/benchmarks/qanimation/qanimation.pro @@ -0,0 +1,18 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qanimation +DEPENDPATH += . +INCLUDEPATH += . + +CONFIG += release +#CONFIG += debug + + +SOURCES += main.cpp \ + dummyobject.cpp \ + dummyanimation.cpp \ + rectanimation.cpp + +HEADERS += dummyobject.h \ + dummyanimation.h \ + rectanimation.h diff --git a/tests/benchmarks/qanimation/rectanimation.cpp b/tests/benchmarks/qanimation/rectanimation.cpp new file mode 100644 index 0000000..75ba476 --- /dev/null +++ b/tests/benchmarks/qanimation/rectanimation.cpp @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "rectanimation.h" +#include "dummyobject.h" + +static inline int interpolateInteger(int from, int to, qreal progress) +{ + return from + (to - from) * progress; +} + + +RectAnimation::RectAnimation(DummyObject *obj) : m_object(obj), m_dura(250) +{ +} + +void RectAnimation::setEndValue(const QRect &rect) +{ + m_end = rect; +} + +void RectAnimation::setStartValue(const QRect &rect) +{ + m_start = rect; +} + +void RectAnimation::setDuration(int d) +{ + m_dura = d; +} + +int RectAnimation::duration() const +{ + return m_dura; +} + + +void RectAnimation::updateCurrentTime(int msecs) +{ + qreal progress = m_easing.valueForProgress( qreal(msecs) / qreal(m_dura) ); + QRect now; + now.setCoords(interpolateInteger(m_start.left(), m_end.left(), progress), + interpolateInteger(m_start.top(), m_end.top(), progress), + interpolateInteger(m_start.right(), m_end.right(), progress), + interpolateInteger(m_start.bottom(), m_end.bottom(), progress)); + + bool changed = (now != m_current); + if (changed) + m_current = now; + + if (state() == Stopped) + return; + + if (m_object) + m_object->setRect(m_current); +} + +void RectAnimation::updateState(QAbstractAnimation::State state) +{ + Q_UNUSED(state); +} diff --git a/tests/benchmarks/qanimation/rectanimation.h b/tests/benchmarks/qanimation/rectanimation.h new file mode 100644 index 0000000..5e088ea --- /dev/null +++ b/tests/benchmarks/qanimation/rectanimation.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtGui> + +#ifndef _RECTANIMATION_H__ + +class DummyObject; + +//this class is even simpler than the dummy +//and uses no QVariant at all +class RectAnimation : public QAbstractAnimation +{ +public: + RectAnimation(DummyObject *obj); + + void setEndValue(const QRect &rect); + void setStartValue(const QRect &rect); + + void setDuration(int d); + int duration() const; + + virtual void updateCurrentTime(int msecs); + virtual void updateState(QAbstractAnimation::State state); + +private: + DummyObject *m_object; + QEasingCurve m_easing; + QRect m_start, m_end, m_current; + int m_dura; +}; + +#endif diff --git a/tests/benchmarks/qdir/qdir.pro b/tests/benchmarks/qdir/qdir.pro new file mode 100644 index 0000000..2cdebfd --- /dev/null +++ b/tests/benchmarks/qdir/qdir.pro @@ -0,0 +1,8 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qdir +DEPENDPATH += . +INCLUDEPATH += . + +# Input +SOURCES += tst_qdir.cpp diff --git a/tests/benchmarks/qdir/tst_qdir.cpp b/tests/benchmarks/qdir/tst_qdir.cpp new file mode 100644 index 0000000..474848d --- /dev/null +++ b/tests/benchmarks/qdir/tst_qdir.cpp @@ -0,0 +1,162 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> + +#ifdef Q_OS_WIN +# include <windows.h> +#else +# include <sys/stat.h> +# include <sys/types.h> +# include <dirent.h> +# include <unistd.h> +#endif + +class Test : public QObject{ + Q_OBJECT +public slots: + void initTestCase() { + QDir testdir = QDir::tempPath(); + + const QString subfolder_name = QLatin1String("test_speed"); + QVERIFY(testdir.mkdir(subfolder_name)); + QVERIFY(testdir.cd(subfolder_name)); + + for (uint i=0; i<10000; ++i) { + QFile file(testdir.absolutePath() + "/testfile_" + QString::number(i)); + file.open(QIODevice::WriteOnly); + } + } + void cleanupTestCase() { + { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + + foreach (const QString &filename, testdir.entryList()) { + testdir.remove(filename); + } + } + const QDir temp = QDir(QDir::tempPath()); + temp.rmdir(QLatin1String("test_speed")); + } +private slots: + void sizeSpeed() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted); + foreach (const QFileInfo &fileInfo, fileInfoList) { + fileInfo.isDir(); + fileInfo.size(); + } + } + } + void sizeSpeedWithoutFilter() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + QBENCHMARK { + QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted); + foreach (const QFileInfo &fileInfo, fileInfoList) { + fileInfo.size(); + } + } + } + void sizeSpeedWithoutFileInfoList() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + QBENCHMARK { + QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); + foreach (const QString &filename, fileList) { + QFileInfo fileInfo(filename); + fileInfo.size(); + } + } + } + void iDontWantAnyStat() { + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + testdir.setSorting(QDir::Unsorted); + testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden); + QBENCHMARK { + QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted); + foreach (const QString &filename, fileList) { + + } + } + } + + void testLowLevel() { +#ifdef Q_OS_WIN + const wchar_t *dirpath = (wchar_t*)testdir.absolutePath().utf16(); + wchar_t appendedPath[MAX_PATH]; + wcscpy(appendedPath, dirpath); + wcscat(appendedPath, L"\\*"); + + WIN32_FIND_DATA fd; + HANDLE hSearch = FindFirstFileW(appendedPath, &fd); + QVERIFY(hSearch == INVALID_HANDLE_VALUE); + + QBENCHMARK { + do { + + } while (FindNextFile(hSearch, &fd)); + } + FindClose(hSearch); +#else + QDir testdir(QDir::tempPath() + QLatin1String("/test_speed")); + DIR *dir = opendir(qPrintable(testdir.absolutePath())); + QVERIFY(dir); + + QVERIFY(!chdir(qPrintable(testdir.absolutePath()))); + QBENCHMARK { + struct dirent *item = readdir(dir); + while (item) { + char *fileName = item->d_name; + + struct stat fileStat; + QVERIFY(!stat(fileName, &fileStat)); + + item = readdir(dir); + } + } + closedir(dir); +#endif + } +}; + +QTEST_MAIN(Test) +#include "tst_qdir.moc" diff --git a/tests/benchmarks/qdiriterator/main.cpp b/tests/benchmarks/qdiriterator/main.cpp index 6e3bef5..ed5192e 100644 --- a/tests/benchmarks/qdiriterator/main.cpp +++ b/tests/benchmarks/qdiriterator/main.cpp @@ -107,7 +107,7 @@ static int posix_helper(const wchar_t *dirpath) wchar_t appendedPath[MAX_PATH]; wcscpy(appendedPath, dirpath); wcscat(appendedPath, L"\\*"); - hSearch = FindFirstFileW(appendedPath, &fd); + hSearch = FindFirstFile(appendedPath, &fd); appendedPath[origDirPathLength] = 0; if (hSearch == INVALID_HANDLE_VALUE) { diff --git a/tests/benchmarks/qdiriterator/qfilesystemiterator.cpp b/tests/benchmarks/qdiriterator/qfilesystemiterator.cpp index 4b9ef7f..1fd11f5 100644 --- a/tests/benchmarks/qdiriterator/qfilesystemiterator.cpp +++ b/tests/benchmarks/qdiriterator/qfilesystemiterator.cpp @@ -108,17 +108,6 @@ QT_BEGIN_NAMESPACE -#ifdef Q_OS_WIN -inline QString convertString(TCHAR* sz) -{ -#ifdef UNICODE - return QString::fromUtf16(sz); -#else - return QString::fromLocal8Bit(sz); -#endif -} -#endif - class QFileSystemIteratorPrivate { public: @@ -202,7 +191,7 @@ QFileSystemIteratorPrivate::~QFileSystemIteratorPrivate() } #ifdef Q_OS_WIN -static bool isDotOrDotDot(const TCHAR* name) +static bool isDotOrDotDot(const wchar_t* name) { if (name[0] == L'.' && name[1] == 0) return true; @@ -339,7 +328,7 @@ bool QFileSystemIteratorPrivate::advanceHelper() if (m_entry->dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) { QByteArray ba = m_dirPaths.top(); ba += '\\'; - ba += convertString(m_entry->cFileName); + ba += QString::fromWCharArray(m_entry->cFileName); pushSubDirectory(ba); } #else @@ -634,7 +623,7 @@ QString QFileSystemIterator::fileName() const if (d->m_currentDirShown == QFileSystemIteratorPrivate::ShowDotDotDir) return QLatin1String("@@"); #ifdef Q_OS_WIN - return convertString(d->m_entry->cFileName); + return QString::fromWCharArray(d->m_entry->cFileName); #else return QString::fromLocal8Bit(d->m_entry->d_name); #endif @@ -659,7 +648,7 @@ QString QFileSystemIterator::filePath() const else if (d->m_entry) { ba += '/'; #ifdef Q_OS_WIN - ba += convertString(d->m_entry->cFileName); + ba += QString::fromWCharArray(d->m_entry->cFileName); #else ba += d->m_entry->d_name; #endif diff --git a/tests/benchmarks/qfile/main.cpp b/tests/benchmarks/qfile/main.cpp index f9579a5..8ef3c44 100644 --- a/tests/benchmarks/qfile/main.cpp +++ b/tests/benchmarks/qfile/main.cpp @@ -3,6 +3,11 @@ ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). ** Contact: Nokia Corporation (qt-info@nokia.com) ** +****************************************************************************/ + +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** ** This file is part of the test suite of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:LGPL$ @@ -275,11 +280,11 @@ void tst_qfile::readBigFile() HANDLE hndl; // ensure we don't account string conversion - TCHAR* cfilename = (TCHAR*)filename.utf16(); + wchar_t* cfilename = (wchar_t*)filename.utf16(); hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); Q_ASSERT(hndl); - TCHAR* nativeBuffer = new TCHAR[BUFSIZE]; + wchar_t* nativeBuffer = new wchar_t[BUFSIZE]; DWORD numberOfBytesRead; QBENCHMARK { @@ -358,7 +363,7 @@ void tst_qfile::seek() HANDLE hndl; // ensure we don't account string conversion - TCHAR* cfilename = (TCHAR*)filename.utf16(); + wchar_t* cfilename = (wchar_t*)filename.utf16(); hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); Q_ASSERT(hndl); @@ -441,7 +446,7 @@ void tst_qfile::open() HANDLE hndl; // ensure we don't account string conversion - TCHAR* cfilename = (TCHAR*)filename.utf16(); + wchar_t* cfilename = (wchar_t*)filename.utf16(); QBENCHMARK { hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); @@ -620,11 +625,11 @@ void tst_qfile::readSmallFiles() HANDLE hndl; // ensure we don't account string conversion - TCHAR* cfilename = (TCHAR*)filename.utf16(); + wchar_t* cfilename = (wchar_t*)filename.utf16(); hndl = CreateFile(cfilename, GENERIC_READ, 0, 0, OPEN_EXISTING, 0, 0); Q_ASSERT(hndl); - TCHAR* nativeBuffer = new TCHAR[BUFSIZE]; + wchar_t* nativeBuffer = new wchar_t[BUFSIZE]; DWORD numberOfBytesRead; QBENCHMARK { do { diff --git a/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro b/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro new file mode 100644 index 0000000..726bb96 --- /dev/null +++ b/tests/benchmarks/qgraphicsitem/qgraphicsitem.pro @@ -0,0 +1,5 @@ +load(qttest_p4) +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 new file mode 100644 index 0000000..91dd28b --- /dev/null +++ b/tests/benchmarks/qgraphicsitem/tst_qgraphicsitem.cpp @@ -0,0 +1,243 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QGraphicsItem> +#include <QGraphicsScene> +#include <QGraphicsView> + +//TESTED_FILES= + +class tst_QGraphicsItem : public QObject +{ + Q_OBJECT + +public: + tst_QGraphicsItem(); + virtual ~tst_QGraphicsItem(); + +public slots: + void init(); + void cleanup(); + +private slots: + void setParentItem(); + void setParentItem_deep(); + void setParentItem_deep_reversed(); + void deleteItemWithManyChildren(); + void setPos_data(); + void setPos(); + void setTransform_data(); + void setTransform(); + void rotate(); + void scale(); + void shear(); + void translate(); + void setRotation(); +}; + +tst_QGraphicsItem::tst_QGraphicsItem() +{ +} + +tst_QGraphicsItem::~tst_QGraphicsItem() +{ +} + +void tst_QGraphicsItem::init() +{ +} + +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::setParentItem_deep_reversed() +{ + QBENCHMARK { + QGraphicsRectItem *lastRect = new QGraphicsRectItem; + for (int i = 0; i < 100; ++i) { + QGraphicsRectItem *parentRect = new QGraphicsRectItem; + lastRect->setParentItem(parentRect); + lastRect = parentRect; + } + delete lastRect; + } +} + +void tst_QGraphicsItem::deleteItemWithManyChildren() +{ + QBENCHMARK { + QGraphicsRectItem *rect = new QGraphicsRectItem; + for (int i = 0; i < 1000; ++i) + new QGraphicsRectItem(rect); + delete rect; + } +} + +void tst_QGraphicsItem::setPos_data() +{ + QTest::addColumn<QPointF>("pos"); + + QTest::newRow("0, 0") << QPointF(0, 0); + QTest::newRow("10, 10") << QPointF(10, 10); + QTest::newRow("-10, -10") << QPointF(-10, -10); +} + +void tst_QGraphicsItem::setPos() +{ + QFETCH(QPointF, pos); + + QGraphicsScene scene; + QGraphicsRectItem *rect = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + rect->setPos(10, 10); + rect->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::setTransform_data() +{ + QTest::addColumn<QTransform>("transform"); + + QTest::newRow("id") << QTransform(); + QTest::newRow("rotate 45z") << QTransform().rotate(45); + QTest::newRow("scale 2x2") << QTransform().scale(2, 2); + QTest::newRow("translate 100, 100") << QTransform().translate(100, 100); + QTest::newRow("rotate 45x 45y 45z") << QTransform().rotate(45, Qt::XAxis) + .rotate(45, Qt::YAxis).rotate(45, Qt::ZAxis); +} + +void tst_QGraphicsItem::setTransform() +{ + QFETCH(QTransform, transform); + + QGraphicsScene scene; + QGraphicsRectItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->setTransform(transform); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::rotate() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->rotate(45); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::scale() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->scale(2, 2); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::shear() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->shear(1.5, 1.5); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::translate() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->translate(100, 100); + item->transform(); // prevent lazy optimizing + } +} + +void tst_QGraphicsItem::setRotation() +{ + QGraphicsScene scene; + QGraphicsItem *item = scene.addRect(QRectF(0, 0, 100, 100)); + + QBENCHMARK { + item->setRotation(45); + item->transform(); // prevent lazy optimizing + } +} + +QTEST_MAIN(tst_QGraphicsItem) +#include "tst_qgraphicsitem.moc" diff --git a/tests/benchmarks/qgraphicsscene/tst_qgraphicsscene.cpp b/tests/benchmarks/qgraphicsscene/tst_qgraphicsscene.cpp index 7a5caa4..172f7d4 100644 --- a/tests/benchmarks/qgraphicsscene/tst_qgraphicsscene.cpp +++ b/tests/benchmarks/qgraphicsscene/tst_qgraphicsscene.cpp @@ -166,6 +166,8 @@ void tst_QGraphicsScene::addItem() } scene.itemAt(0, 0); } + //let QGraphicsScene::_q_polishItems be called so ~QGraphicsItem doesn't spend all his time cleaning the unpolished list + qApp->processEvents(); } void tst_QGraphicsScene::itemAt_data() @@ -220,6 +222,9 @@ void tst_QGraphicsScene::itemAt() QBENCHMARK { scene.itemAt(0, 0); } + + //let QGraphicsScene::_q_polishItems be called so ~QGraphicsItem doesn't spend all his time cleaning the unpolished list + qApp->processEvents(); } QTEST_MAIN(tst_QGraphicsScene) diff --git a/tests/benchmarks/qgraphicsview/benchapps/scrolltest/main.cpp b/tests/benchmarks/qgraphicsview/benchapps/scrolltest/main.cpp index 774c2f8..324143f 100644 --- a/tests/benchmarks/qgraphicsview/benchapps/scrolltest/main.cpp +++ b/tests/benchmarks/qgraphicsview/benchapps/scrolltest/main.cpp @@ -133,7 +133,7 @@ int main(int argc, char *argv[]) #if 0 ItemMover mover(scrollItem); #endif - + CountView view; view.setScene(&scene); view.setSceneRect(-25, -25, 150, 150); diff --git a/tests/benchmarks/qgraphicsview/images/wine-big.jpeg b/tests/benchmarks/qgraphicsview/images/wine-big.jpeg Binary files differnew file mode 100644 index 0000000..9900a50 --- /dev/null +++ b/tests/benchmarks/qgraphicsview/images/wine-big.jpeg diff --git a/tests/benchmarks/qgraphicsview/images/wine.jpeg b/tests/benchmarks/qgraphicsview/images/wine.jpeg Binary files differnew file mode 100644 index 0000000..8fe1d3a --- /dev/null +++ b/tests/benchmarks/qgraphicsview/images/wine.jpeg diff --git a/tests/benchmarks/qgraphicsview/qgraphicsview.qrc b/tests/benchmarks/qgraphicsview/qgraphicsview.qrc index 9f280dd..3681648 100644 --- a/tests/benchmarks/qgraphicsview/qgraphicsview.qrc +++ b/tests/benchmarks/qgraphicsview/qgraphicsview.qrc @@ -1,6 +1,8 @@ <!DOCTYPE RCC><RCC version="1.0"> <qresource> <file>images/designer.png</file> + <file>images/wine.jpeg</file> + <file>images/wine-big.jpeg</file> <file>random.data</file> </qresource> </RCC> diff --git a/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp b/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp index e06930c..464396f 100644 --- a/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp +++ b/tests/benchmarks/qgraphicsview/tst_qgraphicsview.cpp @@ -122,6 +122,10 @@ private slots: void imageRiver(); void textRiver_data(); void textRiver(); + void moveItemCache_data(); + void moveItemCache(); + void paintItemCache_data(); + void paintItemCache(); }; tst_QGraphicsView::tst_QGraphicsView() @@ -688,5 +692,211 @@ void tst_QGraphicsView::textRiver() } } +class AnimatedPixmapCacheItem : public QGraphicsPixmapItem +{ +public: + AnimatedPixmapCacheItem(int x, int y, QGraphicsItem *parent = 0) + : QGraphicsPixmapItem(parent) + { + xspeed = x; + yspeed = y; + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) + { + QGraphicsPixmapItem::paint(painter,option,widget); + //We just want to wait, and we don't want to process the event loop with qWait + QTest::qSleep(3); + } +protected: + void advance(int i) + { + if (!i) + return; + int x = int(pos().x()) + pixmap().width(); + x += xspeed; + x = (x % (300 + pixmap().width() * 2)) - pixmap().width(); + int y = int(pos().y()) + pixmap().width(); + y += yspeed; + y = (y % (300 + pixmap().width() * 2)) - pixmap().width(); + setPos(x, y); + } + +private: + int xspeed; + int yspeed; +}; + +void tst_QGraphicsView::moveItemCache_data() +{ + QTest::addColumn<int>("direction"); + QTest::addColumn<bool>("rotation"); + QTest::addColumn<int>("cacheMode"); + QTest::newRow("Horizontal movement : ItemCoordinate Cache") << 0 << false << (int)QGraphicsItem::ItemCoordinateCache; + QTest::newRow("Horizontal movement : DeviceCoordinate Cache") << 0 << false << (int)QGraphicsItem::DeviceCoordinateCache; + QTest::newRow("Horizontal movement : No Cache") << 0 << false << (int)QGraphicsItem::NoCache; + QTest::newRow("Vertical + Horizontal movement : ItemCoordinate Cache") << 2 << false << (int)QGraphicsItem::ItemCoordinateCache; + QTest::newRow("Vertical + Horizontal movement : DeviceCoordinate Cache") << 2 << false << (int)QGraphicsItem::DeviceCoordinateCache; + QTest::newRow("Vertical + Horizontal movement : No Cache") << 2 << false << (int)QGraphicsItem::NoCache; + QTest::newRow("Horizontal movement + Rotation : ItemCoordinate Cache") << 0 << true << (int)QGraphicsItem::ItemCoordinateCache; + QTest::newRow("Horizontal movement + Rotation : DeviceCoordinate Cache") << 0 << true << (int)QGraphicsItem::DeviceCoordinateCache; + QTest::newRow("Horizontal movement + Rotation : No Cache") << 0 << true << (int)QGraphicsItem::NoCache; +} + +void tst_QGraphicsView::moveItemCache() +{ + QFETCH(int, direction); + QFETCH(bool, rotation); + QFETCH(int, cacheMode); + + QGraphicsScene scene(0, 0, 300, 300); + + CountPaintEventView view(&scene); + view.resize(600, 600); + view.setFrameStyle(0); + view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + view.show(); + + QPixmap pix(":/images/wine.jpeg"); + QVERIFY(!pix.isNull()); + + QList<QGraphicsItem *> items; + QFile file(":/random.data"); + QVERIFY(file.open(QIODevice::ReadOnly)); + QDataStream str(&file); + for (int i = 0; i < 50; ++i) { + AnimatedPixmapCacheItem *item; + if (direction == 0) item = new AnimatedPixmapCacheItem((i % 4) + 1, 0); + if (direction == 1) item = new AnimatedPixmapCacheItem(0, (i % 4) + 1); + if (direction == 2) item = new AnimatedPixmapCacheItem((i % 4) + 1, (i % 4) + 1); + item->setPixmap(pix); + item->setCacheMode((QGraphicsItem::CacheMode)cacheMode); + if (rotation) + item->setTransform(QTransform().rotate(45)); + int rnd1, rnd2; + str >> rnd1 >> rnd2; + item->setPos(-pix.width() + rnd1 % (view.width() + pix.width()), + -pix.height() + rnd2 % (view.height() + pix.height())); + scene.addItem(item); + } + + view.count = 0; + + QBENCHMARK { +#ifdef CALLGRIND_DEBUG + CALLGRIND_START_INSTRUMENTATION +#endif + for (int i = 0; i < 100; ++i) { + scene.advance(); + while (view.count < (i+1)) + qApp->processEvents(); + } +#ifdef CALLGRIND_DEBUG + CALLGRIND_STOP_INSTRUMENTATION +#endif + } +} + +class UpdatedPixmapCacheItem : public QGraphicsPixmapItem +{ +public: + UpdatedPixmapCacheItem(bool partial, QGraphicsItem *parent = 0) + : QGraphicsPixmapItem(parent), partial(partial) + { + } + + void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0) + { + QGraphicsPixmapItem::paint(painter,option,widget); + } +protected: + void advance(int i) + { + if (partial) + update(QRectF(boundingRect().center().x(), boundingRect().center().x(), 30, 30)); + else + update(); + } + +private: + bool partial; +}; + +void tst_QGraphicsView::paintItemCache_data() +{ + QTest::addColumn<bool>("updatePartial"); + QTest::addColumn<bool>("rotation"); + QTest::addColumn<int>("cacheMode"); + QTest::newRow("Partial Update : ItemCoordinate Cache") << true << false << (int)QGraphicsItem::ItemCoordinateCache; + QTest::newRow("Partial Update : DeviceCoordinate Cache") << true << false << (int)QGraphicsItem::DeviceCoordinateCache; + QTest::newRow("Partial Update : No Cache") << true << false << (int)QGraphicsItem::NoCache; + QTest::newRow("Full Update : ItemCoordinate Cache") << false << false << (int)QGraphicsItem::ItemCoordinateCache; + QTest::newRow("Full Update : DeviceCoordinate Cache") << false << false << (int)QGraphicsItem::DeviceCoordinateCache; + QTest::newRow("Full Update : No Cache") << false << false << (int)QGraphicsItem::NoCache; + QTest::newRow("Partial Update : ItemCoordinate Cache item rotated") << true << true << (int)QGraphicsItem::ItemCoordinateCache; + QTest::newRow("Partial Update : DeviceCoordinate Cache item rotated") << true << true << (int)QGraphicsItem::DeviceCoordinateCache; + QTest::newRow("Partial Update : No Cache item rotated") << true << true << (int)QGraphicsItem::NoCache; + QTest::newRow("Full Update : ItemCoordinate Cache item rotated") << false << true << (int)QGraphicsItem::ItemCoordinateCache; + QTest::newRow("Full Update : DeviceCoordinate Cache item rotated") << false << true << (int)QGraphicsItem::DeviceCoordinateCache; + QTest::newRow("Full Update : No Cache item rotated") << false << true <<(int)QGraphicsItem::NoCache; +} + +void tst_QGraphicsView::paintItemCache() +{ + QFETCH(bool, updatePartial); + QFETCH(bool, rotation); + QFETCH(int, cacheMode); + + QGraphicsScene scene(0, 0, 300, 300); + + CountPaintEventView view(&scene); + view.resize(600, 600); + view.setFrameStyle(0); + view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); + view.show(); + + QPixmap pix(":/images/wine.jpeg"); + QVERIFY(!pix.isNull()); + + QList<QGraphicsItem *> items; + QFile file(":/random.data"); + QVERIFY(file.open(QIODevice::ReadOnly)); + QDataStream str(&file); + UpdatedPixmapCacheItem *item = new UpdatedPixmapCacheItem(updatePartial); + item->setPixmap(pix); + item->setCacheMode((QGraphicsItem::CacheMode)cacheMode); + if (rotation) + item->setTransform(QTransform().rotate(45)); + item->setPos(-100, -100); + scene.addItem(item); + + QPixmap pix2(":/images/wine-big.jpeg"); + item = new UpdatedPixmapCacheItem(updatePartial); + item->setPixmap(pix2); + item->setCacheMode((QGraphicsItem::CacheMode)cacheMode); + if (rotation) + item->setTransform(QTransform().rotate(45)); + item->setPos(0, 0); + scene.addItem(item); + + view.count = 0; + + QBENCHMARK { +#ifdef CALLGRIND_DEBUG + CALLGRIND_START_INSTRUMENTATION +#endif + for (int i = 0; i < 50; ++i) { + scene.advance(); + while (view.count < (i+1)) + qApp->processEvents(); + } +#ifdef CALLGRIND_DEBUG + CALLGRIND_STOP_INSTRUMENTATION +#endif + } +} + QTEST_MAIN(tst_QGraphicsView) #include "tst_qgraphicsview.moc" diff --git a/tests/benchmarks/qiodevice/main.cpp b/tests/benchmarks/qiodevice/main.cpp index 4b92786..653f355 100644 --- a/tests/benchmarks/qiodevice/main.cpp +++ b/tests/benchmarks/qiodevice/main.cpp @@ -66,8 +66,10 @@ void tst_qiodevice::read_data() QTest::newRow("100k") << qint64(100 * 1024); QTest::newRow("1000k") << qint64(1000 * 1024); QTest::newRow("10000k") << qint64(10000 * 1024); +#ifndef Q_OS_SYMBIAN // Symbian devices don't (yet) have enough available RAM to run these QTest::newRow("100000k") << qint64(100000 * 1024); QTest::newRow("1000000k") << qint64(1000000 * 1024); +#endif } void tst_qiodevice::read_old() diff --git a/tests/benchmarks/qiodevice/qiodevice.pro b/tests/benchmarks/qiodevice/qiodevice.pro index 59b6302..749a4d6 100755 --- a/tests/benchmarks/qiodevice/qiodevice.pro +++ b/tests/benchmarks/qiodevice/qiodevice.pro @@ -1,6 +1,7 @@ load(qttest_p4) TEMPLATE = app TARGET = tst_qiodevice +TARGET.EPOCHEAPSIZE = 0x100000 0x2000000 DEPENDPATH += . INCLUDEPATH += . diff --git a/tests/benchmarks/qmatrix4x4/qmatrix4x4.pro b/tests/benchmarks/qmatrix4x4/qmatrix4x4.pro new file mode 100644 index 0000000..e82d9de --- /dev/null +++ b/tests/benchmarks/qmatrix4x4/qmatrix4x4.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qmatrix4x4 + +SOURCES += tst_qmatrix4x4.cpp + diff --git a/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp b/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp new file mode 100644 index 0000000..f80a142 --- /dev/null +++ b/tests/benchmarks/qmatrix4x4/tst_qmatrix4x4.cpp @@ -0,0 +1,672 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtOpenGL module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtTest/QtTest> +#include <QtGui/qmatrix4x4.h> + +class tst_QMatrix4x4 : public QObject +{ + Q_OBJECT +public: + tst_QMatrix4x4() {} + ~tst_QMatrix4x4() {} + +private slots: + void multiply_data(); + void multiply(); + + void multiplyInPlace_data(); + void multiplyInPlace(); + + void multiplyDirect_data(); + void multiplyDirect(); + + void mapVector3D_data(); + void mapVector3D(); + + void mapVector2D_data(); + void mapVector2D(); + + void mapVectorDirect_data(); + void mapVectorDirect(); + + void compareTranslate_data(); + void compareTranslate(); + + void compareTranslateAfterScale_data(); + void compareTranslateAfterScale(); + + void compareTranslateAfterRotate_data(); + void compareTranslateAfterRotate(); + + void compareScale_data(); + void compareScale(); + + void compareScaleAfterTranslate_data(); + void compareScaleAfterTranslate(); + + void compareScaleAfterRotate_data(); + void compareScaleAfterRotate(); + + void compareRotate_data(); + void compareRotate(); + + void compareRotateAfterTranslate_data(); + void compareRotateAfterTranslate(); + + void compareRotateAfterScale_data(); + void compareRotateAfterScale(); +}; + +static qreal const generalValues[16] = + {1.0f, 2.0f, 3.0f, 4.0f, + 5.0f, 6.0f, 7.0f, 8.0f, + 9.0f, 10.0f, 11.0f, 12.0f, + 13.0f, 14.0f, 15.0f, 16.0f}; + +void tst_QMatrix4x4::multiply_data() +{ + QTest::addColumn<QMatrix4x4>("m1"); + QTest::addColumn<QMatrix4x4>("m2"); + + QTest::newRow("identity * identity") + << QMatrix4x4() << QMatrix4x4(); + QTest::newRow("identity * general") + << QMatrix4x4() << QMatrix4x4(generalValues); + QTest::newRow("general * identity") + << QMatrix4x4(generalValues) << QMatrix4x4(); + QTest::newRow("general * general") + << QMatrix4x4(generalValues) << QMatrix4x4(generalValues); +} + +QMatrix4x4 mresult; + +void tst_QMatrix4x4::multiply() +{ + QFETCH(QMatrix4x4, m1); + QFETCH(QMatrix4x4, m2); + + QMatrix4x4 m3; + + QBENCHMARK { + m3 = m1 * m2; + } + + // Force the result to be stored so the compiler doesn't + // optimize away the contents of the benchmark loop. + mresult = m3; +} + +void tst_QMatrix4x4::multiplyInPlace_data() +{ + multiply_data(); +} + +void tst_QMatrix4x4::multiplyInPlace() +{ + QFETCH(QMatrix4x4, m1); + QFETCH(QMatrix4x4, m2); + + QMatrix4x4 m3; + + QBENCHMARK { + m3 = m1; + m3 *= m2; + } + + // Force the result to be stored so the compiler doesn't + // optimize away the contents of the benchmark loop. + mresult = m3; +} + +// Use a direct naive multiplication algorithm. This is used +// to compare against the optimized routines to see if they are +// actually faster than the naive implementation. +void tst_QMatrix4x4::multiplyDirect_data() +{ + multiply_data(); +} +void tst_QMatrix4x4::multiplyDirect() +{ + QFETCH(QMatrix4x4, m1); + QFETCH(QMatrix4x4, m2); + + QMatrix4x4 m3; + + const float *m1data = m1.constData(); + const float *m2data = m2.constData(); + float *m3data = m3.data(); + + QBENCHMARK { + for (int row = 0; row < 4; ++row) { + for (int col = 0; col < 4; ++col) { + m3data[col * 4 + row] = 0.0f; + for (int j = 0; j < 4; ++j) { + m3data[col * 4 + row] += + m1data[j * 4 + row] * m2data[col * 4 + j]; + } + } + } + } +} + +QVector3D vresult; + +void tst_QMatrix4x4::mapVector3D_data() +{ + QTest::addColumn<QMatrix4x4>("m1"); + + QTest::newRow("identity") << QMatrix4x4(); + QTest::newRow("general") << QMatrix4x4(generalValues); + + QMatrix4x4 t1; + t1.translate(-100.5f, 64.0f, 75.25f); + QTest::newRow("translate3D") << t1; + + QMatrix4x4 t2; + t2.translate(-100.5f, 64.0f); + QTest::newRow("translate2D") << t2; + + QMatrix4x4 s1; + s1.scale(-100.5f, 64.0f, 75.25f); + QTest::newRow("scale3D") << s1; + + QMatrix4x4 s2; + s2.scale(-100.5f, 64.0f); + QTest::newRow("scale2D") << s2; +} +void tst_QMatrix4x4::mapVector3D() +{ + QFETCH(QMatrix4x4, m1); + + QVector3D v(10.5f, -2.0f, 3.0f); + QVector3D result; + + m1.inferSpecialType(); + + QBENCHMARK { + result = m1 * v; + } + + // Force the result to be stored so the compiler doesn't + // optimize away the contents of the benchmark loop. + vresult = result; +} + +QPointF vresult2; + +void tst_QMatrix4x4::mapVector2D_data() +{ + mapVector3D_data(); +} +void tst_QMatrix4x4::mapVector2D() +{ + QFETCH(QMatrix4x4, m1); + + QPointF v(10.5f, -2.0f); + QPointF result; + + m1.inferSpecialType(); + + QBENCHMARK { + result = m1 * v; + } + + // Force the result to be stored so the compiler doesn't + // optimize away the contents of the benchmark loop. + vresult2 = result; +} + +// Use a direct naive multiplication algorithm. This is used +// to compare against the optimized routines to see if they are +// actually faster than the naive implementation. +void tst_QMatrix4x4::mapVectorDirect_data() +{ + mapVector3D_data(); +} +void tst_QMatrix4x4::mapVectorDirect() +{ + QFETCH(QMatrix4x4, m1); + + const float *m1data = m1.constData(); + float v[4] = {10.5f, -2.0f, 3.0f, 1.0f}; + float result[4]; + + QBENCHMARK { + for (int row = 0; row < 4; ++row) { + result[row] = 0.0f; + for (int col = 0; col < 4; ++col) { + result[row] += m1data[col * 4 + row] * v[col]; + } + } + result[0] /= result[3]; + result[1] /= result[3]; + result[2] /= result[3]; + } +} + +// Compare the performance of QTransform::translate() to +// QMatrix4x4::translate(). +void tst_QMatrix4x4::compareTranslate_data() +{ + QTest::addColumn<bool>("useQTransform"); + QTest::addColumn<QVector3D>("translation"); + + QTest::newRow("QTransform::translate(0, 0, 0)") + << true << QVector3D(0, 0, 0); + QTest::newRow("QMatrix4x4::translate(0, 0, 0)") + << false << QVector3D(0, 0, 0); + + QTest::newRow("QTransform::translate(1, 2, 0)") + << true << QVector3D(1, 2, 0); + QTest::newRow("QMatrix4x4::translate(1, 2, 0)") + << false << QVector3D(1, 2, 0); + + QTest::newRow("QTransform::translate(1, 2, 4)") + << true << QVector3D(1, 2, 4); + QTest::newRow("QMatrix4x4::translate(1, 2, 4)") + << false << QVector3D(1, 2, 4); +} +void tst_QMatrix4x4::compareTranslate() +{ + QFETCH(bool, useQTransform); + QFETCH(QVector3D, translation); + + qreal x = translation.x(); + qreal y = translation.y(); + qreal z = translation.z(); + + if (useQTransform) { + QTransform t; + QBENCHMARK { + t.translate(x, y); + } + } else if (z == 0.0f) { + QMatrix4x4 m; + QBENCHMARK { + m.translate(x, y); + } + } else { + QMatrix4x4 m; + QBENCHMARK { + m.translate(x, y, z); + } + } +} + +// Compare the performance of QTransform::translate() to +// QMatrix4x4::translate() after priming the matrix with a scale(). +void tst_QMatrix4x4::compareTranslateAfterScale_data() +{ + compareTranslate_data(); +} +void tst_QMatrix4x4::compareTranslateAfterScale() +{ + QFETCH(bool, useQTransform); + QFETCH(QVector3D, translation); + + qreal x = translation.x(); + qreal y = translation.y(); + qreal z = translation.z(); + + if (useQTransform) { + QTransform t; + t.scale(3, 4); + QBENCHMARK { + t.translate(x, y); + } + } else if (z == 0.0f) { + QMatrix4x4 m; + m.scale(3, 4); + QBENCHMARK { + m.translate(x, y); + } + } else { + QMatrix4x4 m; + m.scale(3, 4, 5); + QBENCHMARK { + m.translate(x, y, z); + } + } +} + +// Compare the performance of QTransform::translate() to +// QMatrix4x4::translate() after priming the matrix with a rotate(). +void tst_QMatrix4x4::compareTranslateAfterRotate_data() +{ + compareTranslate_data(); +} +void tst_QMatrix4x4::compareTranslateAfterRotate() +{ + QFETCH(bool, useQTransform); + QFETCH(QVector3D, translation); + + qreal x = translation.x(); + qreal y = translation.y(); + qreal z = translation.z(); + + if (useQTransform) { + QTransform t; + t.rotate(45.0f); + QBENCHMARK { + t.translate(x, y); + } + } else if (z == 0.0f) { + QMatrix4x4 m; + m.rotate(45.0f, 0, 0, 1); + QBENCHMARK { + m.translate(x, y); + } + } else { + QMatrix4x4 m; + m.rotate(45.0f, 0, 0, 1); + QBENCHMARK { + m.translate(x, y, z); + } + } +} + +// Compare the performance of QTransform::scale() to +// QMatrix4x4::scale(). +void tst_QMatrix4x4::compareScale_data() +{ + QTest::addColumn<bool>("useQTransform"); + QTest::addColumn<QVector3D>("scale"); + + QTest::newRow("QTransform::scale(1, 1, 1)") + << true << QVector3D(1, 1, 1); + QTest::newRow("QMatrix4x4::scale(1, 1, 1)") + << false << QVector3D(1, 1, 1); + + QTest::newRow("QTransform::scale(3, 6, 1)") + << true << QVector3D(3, 6, 1); + QTest::newRow("QMatrix4x4::scale(3, 6, 1)") + << false << QVector3D(3, 6, 1); + + QTest::newRow("QTransform::scale(3, 6, 4)") + << true << QVector3D(3, 6, 4); + QTest::newRow("QMatrix4x4::scale(3, 6, 4)") + << false << QVector3D(3, 6, 4); +} +void tst_QMatrix4x4::compareScale() +{ + QFETCH(bool, useQTransform); + QFETCH(QVector3D, scale); + + qreal x = scale.x(); + qreal y = scale.y(); + qreal z = scale.z(); + + if (useQTransform) { + QTransform t; + QBENCHMARK { + t.scale(x, y); + } + } else if (z == 1.0f) { + QMatrix4x4 m; + QBENCHMARK { + m.scale(x, y); + } + } else { + QMatrix4x4 m; + QBENCHMARK { + m.scale(x, y, z); + } + } +} + +// Compare the performance of QTransform::scale() to +// QMatrix4x4::scale() after priming the matrix with a translate(). +void tst_QMatrix4x4::compareScaleAfterTranslate_data() +{ + compareScale_data(); +} +void tst_QMatrix4x4::compareScaleAfterTranslate() +{ + QFETCH(bool, useQTransform); + QFETCH(QVector3D, scale); + + qreal x = scale.x(); + qreal y = scale.y(); + qreal z = scale.z(); + + if (useQTransform) { + QTransform t; + t.translate(20, 34); + QBENCHMARK { + t.scale(x, y); + } + } else if (z == 1.0f) { + QMatrix4x4 m; + m.translate(20, 34); + QBENCHMARK { + m.scale(x, y); + } + } else { + QMatrix4x4 m; + m.translate(20, 34, 42); + QBENCHMARK { + m.scale(x, y, z); + } + } +} + +// Compare the performance of QTransform::scale() to +// QMatrix4x4::scale() after priming the matrix with a rotate(). +void tst_QMatrix4x4::compareScaleAfterRotate_data() +{ + compareScale_data(); +} +void tst_QMatrix4x4::compareScaleAfterRotate() +{ + QFETCH(bool, useQTransform); + QFETCH(QVector3D, scale); + + qreal x = scale.x(); + qreal y = scale.y(); + qreal z = scale.z(); + + if (useQTransform) { + QTransform t; + t.rotate(45.0f); + QBENCHMARK { + t.scale(x, y); + } + } else if (z == 1.0f) { + QMatrix4x4 m; + m.rotate(45.0f, 0, 0, 1); + QBENCHMARK { + m.scale(x, y); + } + } else { + QMatrix4x4 m; + m.rotate(45.0f, 0, 0, 1); + QBENCHMARK { + m.scale(x, y, z); + } + } +} + +// Compare the performance of QTransform::rotate() to +// QMatrix4x4::rotate(). +void tst_QMatrix4x4::compareRotate_data() +{ + QTest::addColumn<bool>("useQTransform"); + QTest::addColumn<qreal>("angle"); + QTest::addColumn<QVector3D>("rotation"); + QTest::addColumn<int>("axis"); + + QTest::newRow("QTransform::rotate(0, ZAxis)") + << true << qreal(0.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); + QTest::newRow("QMatrix4x4::rotate(0, ZAxis)") + << false << qreal(0.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); + + QTest::newRow("QTransform::rotate(45, ZAxis)") + << true << qreal(45.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); + QTest::newRow("QMatrix4x4::rotate(45, ZAxis)") + << false << qreal(45.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); + + QTest::newRow("QTransform::rotate(90, ZAxis)") + << true << qreal(90.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); + QTest::newRow("QMatrix4x4::rotate(90, ZAxis)") + << false << qreal(90.0f) << QVector3D(0, 0, 1) << int(Qt::ZAxis); + + QTest::newRow("QTransform::rotate(0, YAxis)") + << true << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); + QTest::newRow("QMatrix4x4::rotate(0, YAxis)") + << false << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); + + QTest::newRow("QTransform::rotate(45, YAxis)") + << true << qreal(45.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); + QTest::newRow("QMatrix4x4::rotate(45, YAxis)") + << false << qreal(45.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); + + QTest::newRow("QTransform::rotate(90, YAxis)") + << true << qreal(90.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); + QTest::newRow("QMatrix4x4::rotate(90, YAxis)") + << false << qreal(90.0f) << QVector3D(0, 1, 0) << int(Qt::YAxis); + + QTest::newRow("QTransform::rotate(0, XAxis)") + << true << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::XAxis); + QTest::newRow("QMatrix4x4::rotate(0, XAxis)") + << false << qreal(0.0f) << QVector3D(0, 1, 0) << int(Qt::XAxis); + + QTest::newRow("QTransform::rotate(45, XAxis)") + << true << qreal(45.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis); + QTest::newRow("QMatrix4x4::rotate(45, XAxis)") + << false << qreal(45.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis); + + QTest::newRow("QTransform::rotate(90, XAxis)") + << true << qreal(90.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis); + QTest::newRow("QMatrix4x4::rotate(90, XAxis)") + << false << qreal(90.0f) << QVector3D(1, 0, 0) << int(Qt::XAxis); +} +void tst_QMatrix4x4::compareRotate() +{ + QFETCH(bool, useQTransform); + QFETCH(qreal, angle); + QFETCH(QVector3D, rotation); + QFETCH(int, axis); + + qreal x = rotation.x(); + qreal y = rotation.y(); + qreal z = rotation.z(); + + if (useQTransform) { + QTransform t; + QBENCHMARK { + t.rotate(angle, Qt::Axis(axis)); + } + } else { + QMatrix4x4 m; + QBENCHMARK { + m.rotate(angle, x, y, z); + } + } +} + +// Compare the performance of QTransform::rotate() to +// QMatrix4x4::rotate() after priming the matrix with a translate(). +void tst_QMatrix4x4::compareRotateAfterTranslate_data() +{ + compareRotate_data(); +} +void tst_QMatrix4x4::compareRotateAfterTranslate() +{ + QFETCH(bool, useQTransform); + QFETCH(qreal, angle); + QFETCH(QVector3D, rotation); + QFETCH(int, axis); + + qreal x = rotation.x(); + qreal y = rotation.y(); + qreal z = rotation.z(); + + if (useQTransform) { + QTransform t; + t.translate(3, 4); + QBENCHMARK { + t.rotate(angle, Qt::Axis(axis)); + } + } else { + QMatrix4x4 m; + m.translate(3, 4, 5); + QBENCHMARK { + m.rotate(angle, x, y, z); + } + } +} + +// Compare the performance of QTransform::rotate() to +// QMatrix4x4::rotate() after priming the matrix with a scale(). +void tst_QMatrix4x4::compareRotateAfterScale_data() +{ + compareRotate_data(); +} +void tst_QMatrix4x4::compareRotateAfterScale() +{ + QFETCH(bool, useQTransform); + QFETCH(qreal, angle); + QFETCH(QVector3D, rotation); + QFETCH(int, axis); + + qreal x = rotation.x(); + qreal y = rotation.y(); + qreal z = rotation.z(); + + if (useQTransform) { + QTransform t; + t.scale(3, 4); + QBENCHMARK { + t.rotate(angle, Qt::Axis(axis)); + } + } else { + QMatrix4x4 m; + m.scale(3, 4, 5); + QBENCHMARK { + m.rotate(angle, x, y, z); + } + } +} + +QTEST_MAIN(tst_QMatrix4x4) + +#include "tst_qmatrix4x4.moc" diff --git a/tests/benchmarks/qnetworkreply/main.cpp b/tests/benchmarks/qnetworkreply/main.cpp new file mode 100644 index 0000000..c54b416 --- /dev/null +++ b/tests/benchmarks/qnetworkreply/main.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ +// This file contains benchmarks for QNetworkReply functions. + +#include <QDebug> +#include <qtest.h> +#include <QtTest/QtTest> +#include <QtNetwork/qnetworkreply.h> +#include <QtNetwork/qnetworkrequest.h> +#include <QtNetwork/qnetworkaccessmanager.h> +#include "../../auto/network-settings.h" + +class tst_qnetworkreply : public QObject +{ + Q_OBJECT +private slots: + void httpLatency(); + +}; + +void tst_qnetworkreply::httpLatency() +{ + QNetworkAccessManager manager; + QBENCHMARK{ + QNetworkRequest request(QUrl("http://" + QtNetworkSettings::serverName() + "/qtest/")); + QNetworkReply* reply = manager.get(request); + connect(reply, SIGNAL(finished()), &QTestEventLoop::instance(), SLOT(exitLoop()), Qt::QueuedConnection); + QTestEventLoop::instance().enterLoop(5); + QVERIFY(!QTestEventLoop::instance().timeout()); + delete reply; + } +} + +QTEST_MAIN(tst_qnetworkreply) + +#include "main.moc" diff --git a/tests/benchmarks/qnetworkreply/qnetworkreply.pro b/tests/benchmarks/qnetworkreply/qnetworkreply.pro new file mode 100644 index 0000000..060acf5 --- /dev/null +++ b/tests/benchmarks/qnetworkreply/qnetworkreply.pro @@ -0,0 +1,13 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qnetworkreply +DEPENDPATH += . +INCLUDEPATH += . + +QT -= gui +QT += network + +CONFIG += release + +# Input +SOURCES += main.cpp diff --git a/tests/benchmarks/qpixmapcache/qpixmapcache.pro b/tests/benchmarks/qpixmapcache/qpixmapcache.pro new file mode 100644 index 0000000..e0d7543 --- /dev/null +++ b/tests/benchmarks/qpixmapcache/qpixmapcache.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qpixmapcache +TEMPLATE = app +# Input +SOURCES += tst_qpixmapcache.cpp diff --git a/tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp b/tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp new file mode 100644 index 0000000..9ce4868 --- /dev/null +++ b/tests/benchmarks/qpixmapcache/tst_qpixmapcache.cpp @@ -0,0 +1,226 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QPixmapCache> +//TESTED_FILES= + +class tst_QPixmapCache : public QObject +{ + Q_OBJECT + +public: + tst_QPixmapCache(); + virtual ~tst_QPixmapCache(); + +public slots: + void init(); + void cleanup(); + +private slots: + void insert_data(); + void insert(); + void find_data(); + void find(); + void styleUseCaseComplexKey(); + void styleUseCaseComplexKey_data(); +}; + +tst_QPixmapCache::tst_QPixmapCache() +{ +} + +tst_QPixmapCache::~tst_QPixmapCache() +{ +} + +void tst_QPixmapCache::init() +{ +} + +void tst_QPixmapCache::cleanup() +{ +} + +void tst_QPixmapCache::insert_data() +{ + QTest::addColumn<bool>("cacheType"); + QTest::newRow("QPixmapCache") << true; + QTest::newRow("QPixmapCache (int API)") << false; +} + +QList<QPixmapCache::Key> keys; + +void tst_QPixmapCache::insert() +{ + QFETCH(bool, cacheType); + QPixmap p; + if (cacheType) { + QBENCHMARK { + for (int i = 0 ; i <= 10000 ; i++) + { + QString tmp; + tmp.sprintf("my-key-%d", i); + QPixmapCache::insert(tmp, p); + } + } + } else { + QBENCHMARK { + for (int i = 0 ; i <= 10000 ; i++) + keys.append(QPixmapCache::insert(p)); + } + } +} + +void tst_QPixmapCache::find_data() +{ + QTest::addColumn<bool>("cacheType"); + QTest::newRow("QPixmapCache") << true; + QTest::newRow("QPixmapCache (int API)") << false; +} + +void tst_QPixmapCache::find() +{ + QFETCH(bool, cacheType); + QPixmap p; + if (cacheType) { + QBENCHMARK { + QString tmp; + for (int i = 0 ; i <= 10000 ; i++) + { + tmp.sprintf("my-key-%d", i); + QPixmapCache::find(tmp, p); + } + } + } else { + QBENCHMARK { + for (int i = 0 ; i <= 10000 ; i++) + QPixmapCache::find(keys.at(i), &p); + } + } + +} + +void tst_QPixmapCache::styleUseCaseComplexKey_data() +{ + QTest::addColumn<bool>("cacheType"); + QTest::newRow("QPixmapCache") << true; + QTest::newRow("QPixmapCache (int API)") << false; +} + +struct styleStruct { + QString key; + uint state; + uint direction; + uint complex; + uint palette; + int width; + int height; + bool operator==(const styleStruct &str) const + { + return str.state == state && str.direction == direction + && str.complex == complex && str.palette == palette && str.width == width + && str.height == height && str.key == key; + } +}; + +uint qHash(const styleStruct &myStruct) +{ + return qHash(myStruct.state); +} + +void tst_QPixmapCache::styleUseCaseComplexKey() +{ + QFETCH(bool, cacheType); + QPixmap p; + if (cacheType) { + QBENCHMARK { + for (int i = 0 ; i <= 10000 ; i++) + { + QString tmp; + tmp.sprintf("%s-%d-%d-%d-%d-%d-%d", QString("my-progressbar-%1").arg(i).toLatin1().constData(), 5, 3, 0, 358, 100, 200); + QPixmapCache::insert(tmp, p); + } + + for (int i = 0 ; i <= 10000 ; i++) + { + QString tmp; + tmp.sprintf("%s-%d-%d-%d-%d-%d-%d", QString("my-progressbar-%1").arg(i).toLatin1().constData(), 5, 3, 0, 358, 100, 200); + QPixmapCache::find(tmp, p); + } + } + } else { + QHash<styleStruct, QPixmapCache::Key> hash; + QBENCHMARK { + for (int i = 0 ; i <= 10000 ; i++) + { + styleStruct myStruct; + myStruct.key = QString("my-progressbar-%1").arg(i); + myStruct.key = 5; + myStruct.key = 4; + myStruct.key = 3; + myStruct.palette = 358; + myStruct.width = 100; + myStruct.key = 200; + QPixmapCache::Key key = QPixmapCache::insert(p); + hash.insert(myStruct, key); + } + for (int i = 0 ; i <= 10000 ; i++) + { + styleStruct myStruct; + myStruct.key = QString("my-progressbar-%1").arg(i); + myStruct.key = 5; + myStruct.key = 4; + myStruct.key = 3; + myStruct.palette = 358; + myStruct.width = 100; + myStruct.key = 200; + QPixmapCache::Key key = hash.value(myStruct); + QPixmapCache::find(key, &p); + } + } + } + +} + + +QTEST_MAIN(tst_QPixmapCache) +#include "tst_qpixmapcache.moc" diff --git a/tests/benchmarks/qquaternion/qquaternion.pro b/tests/benchmarks/qquaternion/qquaternion.pro new file mode 100644 index 0000000..cd68423 --- /dev/null +++ b/tests/benchmarks/qquaternion/qquaternion.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qquaternion + +SOURCES += tst_qquaternion.cpp + diff --git a/tests/benchmarks/qquaternion/tst_qquaternion.cpp b/tests/benchmarks/qquaternion/tst_qquaternion.cpp new file mode 100644 index 0000000..a9f1818 --- /dev/null +++ b/tests/benchmarks/qquaternion/tst_qquaternion.cpp @@ -0,0 +1,124 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QQuaternion> + +//TESTED_FILES= + +class tst_QQuaternion : public QObject +{ + Q_OBJECT + +public: + tst_QQuaternion(); + virtual ~tst_QQuaternion(); + +public slots: + void init(); + void cleanup(); + +private slots: + void multiply_data(); + void multiply(); +}; + +tst_QQuaternion::tst_QQuaternion() +{ +} + +tst_QQuaternion::~tst_QQuaternion() +{ +} + +void tst_QQuaternion::init() +{ +} + +void tst_QQuaternion::cleanup() +{ +} + +void tst_QQuaternion::multiply_data() +{ + QTest::addColumn<qreal>("x1"); + QTest::addColumn<qreal>("y1"); + QTest::addColumn<qreal>("z1"); + QTest::addColumn<qreal>("w1"); + QTest::addColumn<qreal>("x2"); + QTest::addColumn<qreal>("y2"); + QTest::addColumn<qreal>("z2"); + QTest::addColumn<qreal>("w2"); + + QTest::newRow("null") + << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f + << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f << (qreal)0.0f; + + QTest::newRow("unitvec") + << (qreal)1.0f << (qreal)0.0f << (qreal)0.0f << (qreal)1.0f + << (qreal)0.0f << (qreal)1.0f << (qreal)0.0f << (qreal)1.0f; + + QTest::newRow("complex") + << (qreal)1.0f << (qreal)2.0f << (qreal)3.0f << (qreal)7.0f + << (qreal)4.0f << (qreal)5.0f << (qreal)6.0f << (qreal)8.0f; +} + +void tst_QQuaternion::multiply() +{ + QFETCH(qreal, x1); + QFETCH(qreal, y1); + QFETCH(qreal, z1); + QFETCH(qreal, w1); + QFETCH(qreal, x2); + QFETCH(qreal, y2); + QFETCH(qreal, z2); + QFETCH(qreal, w2); + + QQuaternion q1(w1, x1, y1, z1); + QQuaternion q2(w2, x2, y2, z2); + + QBENCHMARK { + QQuaternion q3 = q1 * q2; + } +} + +QTEST_MAIN(tst_QQuaternion) +#include "tst_qquaternion.moc" diff --git a/tests/benchmarks/qscriptengine/qscriptengine.pro b/tests/benchmarks/qscriptengine/qscriptengine.pro new file mode 100644 index 0000000..22bbccd --- /dev/null +++ b/tests/benchmarks/qscriptengine/qscriptengine.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qscriptengine + +SOURCES += tst_qscriptengine.cpp + +QT += script diff --git a/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp b/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp new file mode 100644 index 0000000..515285d --- /dev/null +++ b/tests/benchmarks/qscriptengine/tst_qscriptengine.cpp @@ -0,0 +1,246 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QtScript> + +//TESTED_FILES= + +class tst_QScriptEngine : public QObject +{ + Q_OBJECT + +public: + tst_QScriptEngine(); + virtual ~tst_QScriptEngine(); + +public slots: + void init(); + void cleanup(); + +private slots: + void constructor(); + void evaluate_data(); + void evaluate(); + void connectAndDisconnect(); + void newObject(); + void newQObject(); + void newFunction(); + void newVariant(); + void collectGarbage(); + void pushAndPopContext(); + void toStringHandle(); + void castValueToQreal(); + void nativeCall(); +}; + +tst_QScriptEngine::tst_QScriptEngine() +{ +} + +tst_QScriptEngine::~tst_QScriptEngine() +{ +} + +void tst_QScriptEngine::init() +{ +} + +void tst_QScriptEngine::cleanup() +{ +} + +void tst_QScriptEngine::constructor() +{ + QBENCHMARK { + QScriptEngine engine; + (void)engine.parent(); + } +} + +void tst_QScriptEngine::evaluate_data() +{ + QTest::addColumn<QString>("code"); + QTest::newRow("empty script") << QString::fromLatin1(""); + QTest::newRow("number literal") << QString::fromLatin1("123"); + QTest::newRow("string literal") << QString::fromLatin1("'ciao'"); + QTest::newRow("regexp literal") << QString::fromLatin1("/foo/gim"); + QTest::newRow("null literal") << QString::fromLatin1("null"); + QTest::newRow("undefined literal") << QString::fromLatin1("undefined"); + QTest::newRow("null literal") << QString::fromLatin1("null"); + QTest::newRow("empty object literal") << QString::fromLatin1("{}"); + QTest::newRow("this") << QString::fromLatin1("this"); + QTest::newRow("object literal with one property") << QString::fromLatin1("{ foo: 123 }"); + QTest::newRow("object literal with two properties") << QString::fromLatin1("{ foo: 123, bar: 456 }"); + QTest::newRow("object literal with many properties") << QString::fromLatin1("{ a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9, j: 10 }"); + QTest::newRow("empty array literal") << QString::fromLatin1("[]"); + QTest::newRow("array literal with one element") << QString::fromLatin1("[1]"); + QTest::newRow("array literal with two elements") << QString::fromLatin1("[1,2]"); + QTest::newRow("array literal with many elements") << QString::fromLatin1("[1,2,3,4,5,6,7,8,9,10,9,8,7,6,5,4,3,2,1]"); + QTest::newRow("empty function definition") << QString::fromLatin1("function foo() { }"); + QTest::newRow("function definition") << QString::fromLatin1("function foo() { return 123; }"); + QTest::newRow("for loop with empty body (1000 iterations)") << QString::fromLatin1("for (i = 0; i < 1000; ++i) {}"); + QTest::newRow("for loop with empty body (10000 iterations)") << QString::fromLatin1("for (i = 0; i < 10000; ++i) {}"); + QTest::newRow("for loop with empty body (100000 iterations)") << QString::fromLatin1("for (i = 0; i < 100000; ++i) {}"); + QTest::newRow("for loop with empty body (1000000 iterations)") << QString::fromLatin1("for (i = 0; i < 1000000; ++i) {}"); + QTest::newRow("for loop (1000 iterations)") << QString::fromLatin1("j = 0; for (i = 0; i < 1000; ++i) { j += i; }; j"); + QTest::newRow("for loop (10000 iterations)") << QString::fromLatin1("j = 0; for (i = 0; i < 10000; ++i) { j += i; }; j"); + QTest::newRow("for loop (100000 iterations)") << QString::fromLatin1("j = 0; for (i = 0; i < 100000; ++i) { j += i; }; j"); + QTest::newRow("for loop (1000000 iterations)") << QString::fromLatin1("j = 0; for (i = 0; i < 1000000; ++i) { j += i; }; j"); + QTest::newRow("assignments") << QString::fromLatin1("a = 1; b = 2; c = 3; d = 4"); + QTest::newRow("while loop (1000 iterations)") << QString::fromLatin1("i = 0; while (i < 1000) { ++i; }; i"); + QTest::newRow("while loop (10000 iterations)") << QString::fromLatin1("i = 0; while (i < 10000) { ++i; }; i"); + QTest::newRow("while loop (100000 iterations)") << QString::fromLatin1("i = 0; while (i < 100000) { ++i; }; i"); + QTest::newRow("while loop (1000000 iterations)") << QString::fromLatin1("i = 0; while (i < 1000000) { ++i; }; i"); + QTest::newRow("function expression") << QString::fromLatin1("(function(a, b, c){ return a + b + c; })(1, 2, 3)"); +} + +void tst_QScriptEngine::evaluate() +{ + QFETCH(QString, code); + QScriptEngine engine; + + QBENCHMARK { + (void)engine.evaluate(code); + } +} + +void tst_QScriptEngine::connectAndDisconnect() +{ + QScriptEngine engine; + QScriptValue fun = engine.evaluate("(function() { })"); + QBENCHMARK { + qScriptConnect(&engine, SIGNAL(destroyed()), QScriptValue(), fun); + qScriptDisconnect(&engine, SIGNAL(destroyed()), QScriptValue(), fun); + } +} + +void tst_QScriptEngine::newObject() +{ + QScriptEngine engine; + QBENCHMARK { + (void)engine.newObject(); + } +} + +void tst_QScriptEngine::newQObject() +{ + QScriptEngine engine; + QBENCHMARK { + (void)engine.newQObject(QCoreApplication::instance()); + } +} + +static QScriptValue testFunction(QScriptContext *, QScriptEngine *) +{ + return 0; +} + +void tst_QScriptEngine::newFunction() +{ + QScriptEngine engine; + QBENCHMARK { + (void)engine.newFunction(testFunction); + } +} + +void tst_QScriptEngine::newVariant() +{ + QScriptEngine engine; + QVariant var(123); + QBENCHMARK { + (void)engine.newVariant(var); + } +} + +void tst_QScriptEngine::collectGarbage() +{ + QScriptEngine engine; + QBENCHMARK { + engine.collectGarbage(); + } +} + +void tst_QScriptEngine::pushAndPopContext() +{ + QScriptEngine engine; + QBENCHMARK { + (void)engine.pushContext(); + engine.popContext(); + } +} + +void tst_QScriptEngine::toStringHandle() +{ + QScriptEngine engine; + QString str = QString::fromLatin1("foobarbaz"); + QBENCHMARK { + (void)engine.toStringHandle(str); + } +} + +void tst_QScriptEngine::castValueToQreal() +{ + QScriptEngine engine; + QScriptValue val(123); + QBENCHMARK { + (void)qscriptvalue_cast<qreal>(val); + } +} + +static QScriptValue native_function(QScriptContext *, QScriptEngine *) +{ + return 42; +} + +void tst_QScriptEngine::nativeCall() +{ + QScriptEngine eng; + eng.globalObject().setProperty("fun", eng.newFunction(native_function)); + QBENCHMARK{ + eng.evaluate("var w = 0; for (i = 0; i < 100000; ++i) {\n" + " w += fun() + fun(); w -= fun(); fun(); w -= fun(); }"); + } +} + + +QTEST_MAIN(tst_QScriptEngine) +#include "tst_qscriptengine.moc" diff --git a/tests/benchmarks/qscriptvalue/qscriptvalue.pro b/tests/benchmarks/qscriptvalue/qscriptvalue.pro new file mode 100644 index 0000000..04ea324 --- /dev/null +++ b/tests/benchmarks/qscriptvalue/qscriptvalue.pro @@ -0,0 +1,7 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qscriptvalue + +SOURCES += tst_qscriptvalue.cpp + +QT += script diff --git a/tests/benchmarks/qscriptvalue/tst_qscriptvalue.cpp b/tests/benchmarks/qscriptvalue/tst_qscriptvalue.cpp new file mode 100644 index 0000000..b637591 --- /dev/null +++ b/tests/benchmarks/qscriptvalue/tst_qscriptvalue.cpp @@ -0,0 +1,205 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QtScript> + +//TESTED_FILES= + +class tst_QScriptValue : public QObject +{ + Q_OBJECT + +public: + tst_QScriptValue(); + virtual ~tst_QScriptValue(); + +public slots: + void init(); + void cleanup(); + +private slots: + void numberConstructor(); + void stringConstructor(); + void call_data(); + void call(); + void construct_data(); + void construct(); + void toString_data(); + void toString(); + void toQObject(); + void property(); + void setProperty(); + void propertyFlags(); +}; + +tst_QScriptValue::tst_QScriptValue() +{ +} + +tst_QScriptValue::~tst_QScriptValue() +{ +} + +void tst_QScriptValue::init() +{ +} + +void tst_QScriptValue::cleanup() +{ +} + +void tst_QScriptValue::numberConstructor() +{ + QBENCHMARK { + (void)QScriptValue(123); + } +} + +void tst_QScriptValue::stringConstructor() +{ + QString str = QString::fromLatin1("ciao"); + QBENCHMARK { + (void)QScriptValue(str); + } +} + +void tst_QScriptValue::call_data() +{ + QTest::addColumn<QString>("code"); + QTest::newRow("empty function") << QString::fromLatin1("(function(){})"); + QTest::newRow("function returning number") << QString::fromLatin1("(function(){ return 123; })"); + QTest::newRow("closure") << QString::fromLatin1("(function(a, b){ return function() { return a + b; }; })(1, 2)"); +} + +void tst_QScriptValue::call() +{ + QFETCH(QString, code); + QScriptEngine engine; + QScriptValue fun = engine.evaluate(code); + QVERIFY(fun.isFunction()); + QBENCHMARK { + (void)fun.call(); + } +} + +void tst_QScriptValue::construct_data() +{ + QTest::addColumn<QString>("code"); + QTest::newRow("empty function") << QString::fromLatin1("(function(){})"); + QTest::newRow("simple constructor") << QString::fromLatin1("(function(){ this.x = 10; this.y = 20; })"); +} + +void tst_QScriptValue::construct() +{ + QFETCH(QString, code); + QScriptEngine engine; + QScriptValue fun = engine.evaluate(code); + QVERIFY(fun.isFunction()); + QBENCHMARK { + (void)fun.construct(); + } +} + +void tst_QScriptValue::toString_data() +{ + QTest::addColumn<QString>("code"); + QTest::newRow("number") << QString::fromLatin1("123"); + QTest::newRow("string") << QString::fromLatin1("'ciao'"); + QTest::newRow("null") << QString::fromLatin1("null"); + QTest::newRow("undefined") << QString::fromLatin1("undefined"); + QTest::newRow("function") << QString::fromLatin1("(function foo(a, b, c) { return a + b + c; })"); +} + +void tst_QScriptValue::toString() +{ + QFETCH(QString, code); + QScriptEngine engine; + QScriptValue val = engine.evaluate(code); + QBENCHMARK { + (void)val.toString(); + } +} + +void tst_QScriptValue::toQObject() +{ + QScriptEngine engine; + QScriptValue obj = engine.newQObject(QCoreApplication::instance()); + QBENCHMARK { + (void)obj.toQObject(); + } +} + +void tst_QScriptValue::property() +{ + QScriptEngine engine; + QScriptValue obj = engine.newObject(); + QString propertyName = QString::fromLatin1("foo"); + obj.setProperty(propertyName, 123); + QBENCHMARK { + (void)obj.property(propertyName); + } +} + +void tst_QScriptValue::setProperty() +{ + QScriptEngine engine; + QScriptValue obj = engine.newObject(); + QString propertyName = QString::fromLatin1("foo"); + QScriptValue val(123); + QBENCHMARK { + obj.setProperty(propertyName, val); + } +} + +void tst_QScriptValue::propertyFlags() +{ + QScriptEngine engine; + QScriptValue obj = engine.newObject(); + QString propertyName = QString::fromLatin1("foo"); + obj.setProperty(propertyName, 123, QScriptValue::SkipInEnumeration | QScriptValue::ReadOnly); + QBENCHMARK { + (void)obj.propertyFlags(propertyName); + } +} + +QTEST_MAIN(tst_QScriptValue) +#include "tst_qscriptvalue.moc" diff --git a/tests/benchmarks/qstring/main.cpp b/tests/benchmarks/qstring/main.cpp new file mode 100644 index 0000000..4f91288 --- /dev/null +++ b/tests/benchmarks/qstring/main.cpp @@ -0,0 +1,141 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include <QStringList> +#include <QFile> +#include <qtest.h> + +class tst_QString: public QObject +{ + Q_OBJECT +private slots: + void equals() const; + void equals_data() const; + void fromUtf8() const; +}; + +void tst_QString::equals() const +{ + QFETCH(QString, a); + QFETCH(QString, b); + + QBENCHMARK { + a == b; + } +} + +void tst_QString::equals_data() const +{ + static const struct { + ushort data[80]; + int dummy; // just to ensure 4-byte alignment + } data = { + { + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, // 16 + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, // 32 + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, // 48 + 64, 64, 64, 64, 64, 64, 64, 64, + 64, 64, 64, 64, 64, 64, 64, 64, // 64 + 64, 64, 64, 64, 96, 96, 96, 96, + 64, 64, 96, 96, 96, 96, 96, 96 // 80 + }, 0 + }; + const QChar *ptr = reinterpret_cast<const QChar *>(data.data); + + QTest::addColumn<QString>("a"); + QTest::addColumn<QString>("b"); + QString base = QString::fromRawData(ptr, 64); + + QTest::newRow("different-length") << base << QString::fromRawData(ptr, 4); + QTest::newRow("same-string") << base << base; + QTest::newRow("same-data") << base << QString::fromRawData(ptr, 64); + + // try to avoid crossing a cache line (that is, at ptr[64]) + QTest::newRow("aligned-aligned-4n") + << QString::fromRawData(ptr, 60) << QString::fromRawData(ptr + 2, 60); + QTest::newRow("aligned-unaligned-4n") + << QString::fromRawData(ptr, 60) << QString::fromRawData(ptr + 1, 60); + QTest::newRow("unaligned-unaligned-4n") + << QString::fromRawData(ptr + 1, 60) << QString::fromRawData(ptr + 3, 60); + + QTest::newRow("aligned-aligned-4n+1") + << QString::fromRawData(ptr, 61) << QString::fromRawData(ptr + 2, 61); + QTest::newRow("aligned-unaligned-4n+1") + << QString::fromRawData(ptr, 61) << QString::fromRawData(ptr + 1, 61); + QTest::newRow("unaligned-unaligned-4n+1") + << QString::fromRawData(ptr + 1, 61) << QString::fromRawData(ptr + 3, 61); + + QTest::newRow("aligned-aligned-4n-1") + << QString::fromRawData(ptr, 59) << QString::fromRawData(ptr + 2, 59); + QTest::newRow("aligned-unaligned-4n-1") + << QString::fromRawData(ptr, 59) << QString::fromRawData(ptr + 1, 59); + QTest::newRow("unaligned-unaligned-4n-1") + << QString::fromRawData(ptr + 1, 59) << QString::fromRawData(ptr + 3, 59); + + QTest::newRow("aligned-aligned-2n") + << QString::fromRawData(ptr, 58) << QString::fromRawData(ptr + 2, 58); + QTest::newRow("aligned-unaligned-2n") + << QString::fromRawData(ptr, 58) << QString::fromRawData(ptr + 1, 58); + QTest::newRow("unaligned-unaligned-2n") + << QString::fromRawData(ptr + 1, 58) << QString::fromRawData(ptr + 3, 58); +} + +void tst_QString::fromUtf8() const +{ + QFile file(SRCDIR "utf-8.txt"); + if (!file.open(QFile::ReadOnly)) { + qFatal("Cannot open input file"); + return; + } + QByteArray data = file.readAll(); + const char *d = data.constData(); + int size = data.size(); + + QBENCHMARK { + QString::fromUtf8(d, size); + } +} + +QTEST_MAIN(tst_QString) + +#include "main.moc" diff --git a/tests/benchmarks/qstring/qstring.pro b/tests/benchmarks/qstring/qstring.pro new file mode 100644 index 0000000..6aad1c0 --- /dev/null +++ b/tests/benchmarks/qstring/qstring.pro @@ -0,0 +1,12 @@ +load(qttest_p4) +TARGET = tst_qstring +QT -= gui +SOURCES += main.cpp + +wince*:{ + DEFINES += SRCDIR=\\\"\\\" +} else { + DEFINES += SRCDIR=\\\"$$PWD/\\\" +} + + diff --git a/tests/benchmarks/qstring/utf-8.txt b/tests/benchmarks/qstring/utf-8.txt new file mode 100644 index 0000000..a8a58de --- /dev/null +++ b/tests/benchmarks/qstring/utf-8.txt @@ -0,0 +1,72 @@ +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français +Språk: Norsk +Γλώσσα: Ελληνικά +Язык: Русский +언어 : 한국어 +言語: 日本語 +Langage : Français diff --git a/tests/benchmarks/qstringbuilder/main.cpp b/tests/benchmarks/qstringbuilder/main.cpp new file mode 100644 index 0000000..b1d4165 --- /dev/null +++ b/tests/benchmarks/qstringbuilder/main.cpp @@ -0,0 +1,464 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the test suite module 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +// Select one of the scenarios below +#define SCENARIO 1 + +#if SCENARIO == 1 +// this is the "no harm done" version. Only operator% is active, +// with NO_CAST * defined +#define P % +#undef QT_USE_FAST_OPERATOR_PLUS +#undef QT_USE_FAST_CONCATENATION +#define QT_NO_CAST_FROM_ASCII +#define QT_NO_CAST_TO_ASCII +#endif + + +#if SCENARIO == 2 +// this is the "full" version. Operator+ is replaced by a QStringBuilder +// based version +// with NO_CAST * defined +#define P + +#define QT_USE_FAST_OPERATOR_PLUS +#define QT_USE_FAST_CONCATENATION +#define QT_NO_CAST_FROM_ASCII +#define QT_NO_CAST_TO_ASCII +#endif + +#if SCENARIO == 3 +// this is the "no harm done" version. Only operator% is active, +// with NO_CAST * _not_ defined +#define P % +#undef QT_USE_FAST_OPERATOR_PLUS +#undef QT_USE_FAST_CONCATENATION +#undef QT_NO_CAST_FROM_ASCII +#undef QT_NO_CAST_TO_ASCII +#endif + +#if SCENARIO == 4 +// this is the "full" version. Operator+ is replaced by a QStringBuilder +// based version +// with NO_CAST * _not_ defined +#define P + +#define QT_USE_FAST_OPERATOR_PLUS +#define QT_USE_FAST_CONCATENATION +#undef QT_NO_CAST_FROM_ASCII +#undef QT_NO_CAST_TO_ASCII +#endif + + +#include <qbytearray.h> +#include <qdebug.h> +#include <qstring.h> +#include <qstringbuilder.h> + +#include <qtest.h> + +#include <string> + +#define COMPARE(a, b) QCOMPARE(a, b) +//#define COMPARE(a, b) + +#define SEP(s) qDebug() << "\n\n-------- " s " ---------"; + +#define LITERAL "some string literal" + +class tst_qstringbuilder : public QObject +{ + Q_OBJECT + +public: + tst_qstringbuilder() + : l1literal(LITERAL), + l1string(LITERAL), + ba(LITERAL), + string(l1string), + stdstring(LITERAL), + stringref(&string, 2, 10), + achar('c'), + r2(QLatin1String(LITERAL LITERAL)), + r3(QLatin1String(LITERAL LITERAL LITERAL)), + r4(QLatin1String(LITERAL LITERAL LITERAL LITERAL)), + r5(QLatin1String(LITERAL LITERAL LITERAL LITERAL LITERAL)) + {} + + +public: + enum { N = 10000 }; + + int run_traditional() + { + int s = 0; + for (int i = 0; i < N; ++i) { +#if 0 + s += QString(l1string + l1string).size(); + s += QString(l1string + l1string + l1string).size(); + s += QString(l1string + l1string + l1string + l1string).size(); + s += QString(l1string + l1string + l1string + l1string + l1string).size(); +#endif + s += QString(achar + l1string + achar).size(); + } + return s; + } + + int run_builder() + { + int s = 0; + for (int i = 0; i < N; ++i) { +#if 0 + s += QString(l1literal P l1literal).size(); + s += QString(l1literal P l1literal P l1literal).size(); + s += QString(l1literal P l1literal P l1literal P l1literal).size(); + s += QString(l1literal P l1literal P l1literal P l1literal P l1literal).size(); +#endif + s += QString(achar % l1literal % achar).size(); + } + return s; + } + +private slots: + + void separator_0() { + qDebug() << "\nIn each block the QStringBuilder based result appear first " + "(with a 'b_' prefix), QStringBased second ('q_' prefix), std::string " + "last ('s_' prefix)\n"; + } + + void separator_1() { SEP("literal + literal (builder first)"); } + + void b_2_l1literal() { + QBENCHMARK { r = l1literal P l1literal; } + COMPARE(r, r2); + } + #ifndef QT_NO_CAST_FROM_ASCII + void b_l1literal_LITERAL() { + QBENCHMARK { r = l1literal P LITERAL; } + COMPARE(r, r2); + } + #endif + void q_2_l1string() { + QBENCHMARK { r = l1string + l1string; } + COMPARE(r, r2); + } + + + void separator_2() { SEP("2 strings"); } + + void b_2_string() { + QBENCHMARK { r = string P string; } + COMPARE(r, r2); + } + void q_2_string() { + QBENCHMARK { r = string + string; } + COMPARE(r, r2); + } + void s_2_string() { + QBENCHMARK { stdr = stdstring + stdstring; } + COMPARE(stdr, stdstring + stdstring); + } + + + void separator_2c() { SEP("2 string refs"); } + + void b_2_stringref() { + QBENCHMARK { r = stringref % stringref; } + COMPARE(r, QString(stringref.toString() + stringref.toString())); + } + void q_2_stringref() { + QBENCHMARK { r = stringref.toString() + stringref.toString(); } + COMPARE(r, QString(stringref % stringref)); + } + + + void separator_2b() { SEP("3 strings"); } + + void b_3_string() { + QBENCHMARK { r = string P string P string; } + COMPARE(r, r3); + } + void q_3_string() { + QBENCHMARK { r = string + string + string; } + COMPARE(r, r3); + } + void s_3_string() { + QBENCHMARK { stdr = stdstring + stdstring + stdstring; } + COMPARE(stdr, stdstring + stdstring + stdstring); + } + + void separator_2e() { SEP("4 strings"); } + + void b_4_string() { + QBENCHMARK { r = string P string P string P string; } + COMPARE(r, r4); + } + void q_4_string() { + QBENCHMARK { r = string + string + string + string; } + COMPARE(r, r4); + } + void s_4_string() { + QBENCHMARK { stdr = stdstring + stdstring + stdstring + stdstring; } + COMPARE(stdr, stdstring + stdstring + stdstring + stdstring); + } + + + + void separator_2a() { SEP("string + literal (builder first)"); } + + void b_string_l1literal() { + QBENCHMARK { r = string % l1literal; } + COMPARE(r, r2); + } + #ifndef QT_NO_CAST_FROM_ASCII + void b_string_LITERAL() { + QBENCHMARK { r = string P LITERAL; } + COMPARE(r, r2); + } + void b_LITERAL_string() { + QBENCHMARK { r = LITERAL P string; } + COMPARE(r, r2); + } + #endif + void b_string_l1string() { + QBENCHMARK { r = string P l1string; } + COMPARE(r, r2); + } + void q_string_l1literal() { + QBENCHMARK { r = string + l1string; } + COMPARE(r, r2); + } + void q_string_l1string() { + QBENCHMARK { r = string + l1string; } + COMPARE(r, r2); + } + void s_LITERAL_string() { + QBENCHMARK { stdr = LITERAL + stdstring; } + COMPARE(stdr, stdstring + stdstring); + } + + + void separator_3() { SEP("3 literals"); } + + void b_3_l1literal() { + QBENCHMARK { r = l1literal P l1literal P l1literal; } + COMPARE(r, r3); + } + void q_3_l1string() { + QBENCHMARK { r = l1string + l1string + l1string; } + COMPARE(r, r3); + } + void s_3_l1string() { + QBENCHMARK { stdr = stdstring + LITERAL + LITERAL; } + COMPARE(stdr, stdstring + stdstring + stdstring); + } + + + void separator_4() { SEP("4 literals"); } + + void b_4_l1literal() { + QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal; } + COMPARE(r, r4); + } + void q_4_l1string() { + QBENCHMARK { r = l1string + l1string + l1string + l1string; } + COMPARE(r, r4); + } + + + void separator_5() { SEP("5 literals"); } + + void b_5_l1literal() { + QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal P l1literal; } + COMPARE(r, r5); + } + + void q_5_l1string() { + QBENCHMARK { r = l1string + l1string + l1string + l1string + l1string; } + COMPARE(r, r5); + } + + + void separator_6() { SEP("4 chars"); } + + void b_string_4_char() { + QBENCHMARK { r = string + achar + achar + achar + achar; } + COMPARE(r, QString(string P achar P achar P achar P achar)); + } + + void q_string_4_char() { + QBENCHMARK { r = string + achar + achar + achar + achar; } + COMPARE(r, QString(string P achar P achar P achar P achar)); + } + + void s_string_4_char() { + QBENCHMARK { stdr = stdstring + 'c' + 'c' + 'c' + 'c'; } + COMPARE(stdr, stdstring + 'c' + 'c' + 'c' + 'c'); + } + + + void separator_7() { SEP("char + string + char"); } + + void b_char_string_char() { + QBENCHMARK { r = achar + string + achar; } + COMPARE(r, QString(achar P string P achar)); + } + + void q_char_string_char() { + QBENCHMARK { r = achar + string + achar; } + COMPARE(r, QString(achar P string P achar)); + } + + void s_char_string_char() { + QBENCHMARK { stdr = 'c' + stdstring + 'c'; } + COMPARE(stdr, 'c' + stdstring + 'c'); + } + + + void separator_8() { SEP("string.arg"); } + + void b_string_arg() { + const QString pattern = l1string + QString::fromLatin1("%1") + l1string; + QBENCHMARK { r = l1literal P string P l1literal; } + COMPARE(r, r3); + } + + void q_string_arg() { + const QString pattern = l1string + QLatin1String("%1") + l1string; + QBENCHMARK { r = pattern.arg(string); } + COMPARE(r, r3); + } + + void q_bytearray_arg() { + QByteArray result; + QBENCHMARK { result = ba + ba + ba; } + } + + + void separator_9() { SEP("QString::reserve()"); } + + void b_reserve() { + QBENCHMARK { + r.clear(); + r = string P string P string P string; + } + COMPARE(r, r4); + } + void b_reserve_lit() { + QBENCHMARK { + r.clear(); + r = string P l1literal P string P string; + } + COMPARE(r, r4); + } + void s_reserve() { + QBENCHMARK { + r.clear(); + r.reserve(string.size() + string.size() + string.size() + string.size()); + r += string; + r += string; + r += string; + r += string; + } + COMPARE(r, r4); + } + void s_reserve_lit() { + QBENCHMARK { + r.clear(); + //r.reserve(string.size() + qstrlen(l1string.latin1()) + // + string.size() + string.size()); + r.reserve(1024); + r += string; + r += l1string; + r += string; + r += string; + } + COMPARE(r, r4); + } + +private: + const QLatin1Literal l1literal; + const QLatin1String l1string; + const QByteArray ba; + const QString string; + const std::string stdstring; + const QStringRef stringref; + const QLatin1Char achar; + const QString r2, r3, r4, r5; + + // short cuts for results + QString r; + std::string stdr; +}; + + +//void operator%(QString, int) {} + +int main(int argc, char *argv[]) +{ + //qDebug() << (QString("xx") * QLatin1String("y")).toString(); + //42 % 3; // Sanity test, should always work. + //QString("x") % 2; // Sanity test, should only compile when the + // operator%(QString, int) is visible. + + if (argc == 2 && (QLatin1String(argv[1]) == QLatin1String("--run-builder") + || QLatin1String(argv[1]) == QLatin1String("-b"))) { + tst_qstringbuilder test; + return test.run_builder(); + } + + if (argc == 2 && (QLatin1String(argv[1]) == QLatin1String("--run-traditional") + || QLatin1String(argv[1]) == QLatin1String("-t"))) { + tst_qstringbuilder test; + return test.run_traditional(); + } + + if (argc == 1) { + QCoreApplication app(argc, argv); + QStringList args = app.arguments(); + tst_qstringbuilder test; + return QTest::qExec(&test, argc, argv); + } + + qDebug() << "Usage: " << argv[0] << " [--run-builder|-r|--run-traditional|-t]"; +} + + +#include "main.moc" diff --git a/tests/benchmarks/qstringbuilder/qstringbuilder.pro b/tests/benchmarks/qstringbuilder/qstringbuilder.pro new file mode 100644 index 0000000..79171b4 --- /dev/null +++ b/tests/benchmarks/qstringbuilder/qstringbuilder.pro @@ -0,0 +1,12 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qstringbuilder + +QMAKE_CXXFLAGS += -g +QMAKE_CFLAGS += -g + +QT -= gui + +CONFIG += release + +SOURCES += main.cpp diff --git a/tests/benchmarks/qstringlist/main.cpp b/tests/benchmarks/qstringlist/main.cpp index 9d5dd49..6af41c0 100644 --- a/tests/benchmarks/qstringlist/main.cpp +++ b/tests/benchmarks/qstringlist/main.cpp @@ -38,32 +38,61 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include <QStringList> -#include <qtest.h> +#include <QtTest> + +#include <sstream> +#include <string> +#include <vector> class tst_QStringList: public QObject { Q_OBJECT + private slots: void join() const; void join_data() const; + void split() const; + void split_data() const; + + void split_std() const; + void split_std_data() const { return split_data(); } + + void split_stdw() const; + void split_stdw_data() const { return split_data(); } + + void split_ba() const; + void split_ba_data() const { return split_data(); } + private: - static QStringList populate(const unsigned int count, - const QString &unit); + static QStringList populateList(const int count, const QString &unit); + static QString populateString(const int count, const QString &unit); }; -QStringList tst_QStringList::populate(const unsigned int count, - const QString &unit) +QStringList tst_QStringList::populateList(const int count, const QString &unit) { QStringList retval; - for(unsigned int i = 0; i < count; ++i) + for (int i = 0; i < count; ++i) retval.append(unit); return retval; } +QString tst_QStringList::populateString(const int count, const QString &unit) +{ + QString retval; + + for (int i = 0; i < count; ++i) { + retval.append(unit); + retval.append(QLatin1Char(':')); + } + + return retval; +} + void tst_QStringList::join() const { QFETCH(QStringList, input); @@ -80,22 +109,85 @@ void tst_QStringList::join_data() const QTest::addColumn<QString>("separator"); QTest::newRow("") - << populate(100, QLatin1String("unit")) + << populateList(100, QLatin1String("unit")) << QString(); QTest::newRow("") - << populate(1000, QLatin1String("unit")) + << populateList(1000, QLatin1String("unit")) << QString(); QTest::newRow("") - << populate(10000, QLatin1String("unit")) + << populateList(10000, QLatin1String("unit")) << QString(); QTest::newRow("") - << populate(100000, QLatin1String("unit")) + << populateList(100000, QLatin1String("unit")) << QString(); } +void tst_QStringList::split() const +{ + QFETCH(QString, input); + const QChar splitChar = ':'; + + QBENCHMARK { + input.split(splitChar); + } +} + +void tst_QStringList::split_data() const +{ + QTest::addColumn<QString>("input"); + QString unit = QLatin1String("unit"); + QTest::newRow("") << populateString(10, unit); + QTest::newRow("") << populateString(100, unit); + QTest::newRow("") << populateString(1000, unit); + QTest::newRow("") << populateString(10000, unit); +} + +void tst_QStringList::split_std() const +{ + QFETCH(QString, input); + const char split_char = ':'; + std::string stdinput = input.toStdString(); + + QBENCHMARK { + std::istringstream split(stdinput); + std::vector<std::string> token; + for (std::string each; + std::getline(split, each, split_char); + token.push_back(each)) + ; + } +} + +void tst_QStringList::split_stdw() const +{ + QFETCH(QString, input); + const wchar_t split_char = ':'; + std::wstring stdinput = input.toStdWString(); + + QBENCHMARK { + std::wistringstream split(stdinput); + std::vector<std::wstring> token; + for (std::wstring each; + std::getline(split, each, split_char); + token.push_back(each)) + ; + } +} + +void tst_QStringList::split_ba() const +{ + QFETCH(QString, input); + const char splitChar = ':'; + QByteArray ba = input.toLatin1(); + + QBENCHMARK { + ba.split(splitChar); + } +} + QTEST_MAIN(tst_QStringList) #include "main.moc" diff --git a/tests/benchmarks/qtableview/qtableview.pro b/tests/benchmarks/qtableview/qtableview.pro new file mode 100644 index 0000000..02bc530 --- /dev/null +++ b/tests/benchmarks/qtableview/qtableview.pro @@ -0,0 +1,6 @@ +load(qttest_p4) +TEMPLATE = app +TARGET = tst_qtableview + +SOURCES += tst_qtableview.cpp + diff --git a/tests/benchmarks/qtableview/tst_qtableview.cpp b/tests/benchmarks/qtableview/tst_qtableview.cpp new file mode 100644 index 0000000..cd55a0d --- /dev/null +++ b/tests/benchmarks/qtableview/tst_qtableview.cpp @@ -0,0 +1,193 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** 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 either Technology Preview License Agreement or the +** Beta Release License Agreement. +** +** 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.0, included in the file LGPL_EXCEPTION.txt in this +** package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** If you are unsure which license is appropriate for your use, please +** contact the sales department at http://qt.nokia.com/contact. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qtest.h> +#include <QDebug> +#include <QTableView> +#include <QImage> +#include <QPainter> + +//TESTED_FILES= + +class QtTestTableModel: public QAbstractTableModel +{ + Q_OBJECT + + +public: + QtTestTableModel(int rows = 0, int columns = 0, QObject *parent = 0) + : QAbstractTableModel(parent), + row_count(rows), + column_count(columns) {} + + int rowCount(const QModelIndex& = QModelIndex()) const { return row_count; } + int columnCount(const QModelIndex& = QModelIndex()) const { return column_count; } + bool isEditable(const QModelIndex &) const { return true; } + + QVariant data(const QModelIndex &idx, int role) const + { + if (!idx.isValid() || idx.row() >= row_count || idx.column() >= column_count) { + qWarning() << "Invalid modelIndex [%d,%d,%p]" << idx; + return QVariant(); + } + + if (role == Qt::DisplayRole || role == Qt::EditRole) + return QString("[%1,%2,%3]").arg(idx.row()).arg(idx.column()).arg(0); + + return QVariant(); + } + + int row_count; + int column_count; +}; + + + + +class tst_QTableView : public QObject +{ + Q_OBJECT + +public: + tst_QTableView(); + virtual ~tst_QTableView(); + +public slots: + void init(); + void cleanup(); + +private slots: + void spanInit(); + void spanDraw(); + void spanSelectColumn(); + void spanSelectAll(); +private: + static inline void spanInit_helper(QTableView *); +}; + +tst_QTableView::tst_QTableView() +{ +} + +tst_QTableView::~tst_QTableView() +{ +} + +void tst_QTableView::init() +{ +} + +void tst_QTableView::cleanup() +{ +} + +void tst_QTableView::spanInit_helper(QTableView *view) +{ + for (int i=0; i < 40; i++) { + view->setSpan(1+i%2, 1+4*i, 1+i%3, 2); + } + + for (int i=1; i < 40; i++) { + view->setSpan(6 + i*7, 4, 4, 50); + } +} + +void tst_QTableView::spanInit() +{ + QtTestTableModel model(500, 500); + QTableView v; + v.setModel(&model); + + QBENCHMARK { + spanInit_helper(&v); + } +} + +void tst_QTableView::spanDraw() +{ + QtTestTableModel model(500, 500); + QTableView v; + v.setModel(&model); + + spanInit_helper(&v); + v.show(); + v.resize(500,500); + QTest::qWait(30); + + QImage image(500, 500, QImage::Format_ARGB32_Premultiplied); + QPainter painter(&image); + QBENCHMARK { + v.render(&painter); + } +} + +void tst_QTableView::spanSelectAll() +{ + QtTestTableModel model(500, 500); + QTableView v; + v.setModel(&model); + + spanInit_helper(&v); + v.show(); + QTest::qWait(30); + + QBENCHMARK { + v.selectAll(); + } +} + +void tst_QTableView::spanSelectColumn() +{ + QtTestTableModel model(500, 500); + QTableView v; + v.setModel(&model); + + spanInit_helper(&v); + v.show(); + QTest::qWait(30); + + QBENCHMARK { + v.selectColumn(22); + } +} + +QTEST_MAIN(tst_QTableView) +#include "tst_qtableview.moc" diff --git a/tests/benchmarks/qvariant/qvariant.pro b/tests/benchmarks/qvariant/qvariant.pro index 68b4a97..63b5442 100644 --- a/tests/benchmarks/qvariant/qvariant.pro +++ b/tests/benchmarks/qvariant/qvariant.pro @@ -3,7 +3,6 @@ TEMPLATE = app TARGET = tst_qvariant DEPENDPATH += . INCLUDEPATH += . -QT -= gui CONFIG += release #CONFIG += debug diff --git a/tests/benchmarks/qvariant/tst_qvariant.cpp b/tests/benchmarks/qvariant/tst_qvariant.cpp index 86a06a9..2d96c29 100644 --- a/tests/benchmarks/qvariant/tst_qvariant.cpp +++ b/tests/benchmarks/qvariant/tst_qvariant.cpp @@ -38,7 +38,9 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ + #include <QtCore> +#include <QtGui/QPixmap> #include <qtest.h> #define ITERATION_COUNT 1e5 @@ -47,64 +49,73 @@ 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 tst_qvariant::doubleVariantCreation() +void tst_qvariant::testBound() { - double d = 0; + qreal d = qreal(.5); QBENCHMARK { for(int i = 0; i < ITERATION_COUNT; ++i) { - QVariant v(d); + d = qBound<qreal>(0, d, 1); } } } -void tst_qvariant::floatVariantCreation() +template <typename T> +static void variantCreation(T val) { - float f = 0; QBENCHMARK { for(int i = 0; i < ITERATION_COUNT; ++i) { - QVariant v(f); + QVariant v(val); } } } +void tst_qvariant::doubleVariantCreation() +{ + variantCreation<double>(0.0); +} + +void tst_qvariant::floatVariantCreation() +{ + variantCreation<float>(0.0f); +} + void tst_qvariant::rectVariantCreation() { - QRect r(1,2,3,4); - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - QVariant v(r); - } - } + variantCreation<QRect>(QRect(1, 2, 3, 4)); } void tst_qvariant::stringVariantCreation() { - QString s; - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - QVariant v(s); - } - } + variantCreation<QString>(QString()); } -void tst_qvariant::doubleVariantSetValue() +void tst_qvariant::pixmapVariantCreation() +{ + variantCreation<QPixmap>(QPixmap()); +} + +template <typename T> +static void variantSetValue(T d) { - double d = 0; QVariant v; QBENCHMARK { for(int i = 0; i < ITERATION_COUNT; ++i) { @@ -113,42 +124,29 @@ void tst_qvariant::doubleVariantSetValue() } } +void tst_qvariant::doubleVariantSetValue() +{ + variantSetValue<double>(0.0); +} + void tst_qvariant::floatVariantSetValue() { - float f = 0; - QVariant v; - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - qVariantSetValue(v, f); - } - } + variantSetValue<float>(0.0f); } void tst_qvariant::rectVariantSetValue() { - QRect r; - QVariant v; - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - qVariantSetValue(v, r); - } - } + variantSetValue<QRect>(QRect()); } void tst_qvariant::stringVariantSetValue() { - QString s; - QVariant v; - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - qVariantSetValue(v, s); - } - } + variantSetValue<QString>(QString()); } -void tst_qvariant::doubleVariantAssignment() +template <typename T> +static void variantAssignment(T d) { - double d = 0; QVariant v; QBENCHMARK { for(int i = 0; i < ITERATION_COUNT; ++i) { @@ -157,37 +155,24 @@ void tst_qvariant::doubleVariantAssignment() } } +void tst_qvariant::doubleVariantAssignment() +{ + variantAssignment<double>(0.0); +} + void tst_qvariant::floatVariantAssignment() { - float f = 0; - QVariant v; - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - v = f; - } - } + variantAssignment<float>(0.0f); } void tst_qvariant::rectVariantAssignment() { - QRect r; - QVariant v; - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - v = r; - } - } + variantAssignment<QRect>(QRect()); } void tst_qvariant::stringVariantAssignment() { - QString s; - QVariant v; - QBENCHMARK { - for(int i = 0; i < ITERATION_COUNT; ++i) { - v = s; - } - } + variantAssignment<QString>(QString()); } QTEST_MAIN(tst_qvariant) |