summaryrefslogtreecommitdiff
path: root/tests/benchmarks/corelib
diff options
context:
space:
mode:
Diffstat (limited to 'tests/benchmarks/corelib')
-rw-r--r--tests/benchmarks/corelib/io/qfileinfo/main.cpp44
-rw-r--r--tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp52
-rw-r--r--tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp47
-rw-r--r--tests/benchmarks/corelib/thread/qmutex/qmutex.pro6
-rw-r--r--tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp131
5 files changed, 279 insertions, 1 deletions
diff --git a/tests/benchmarks/corelib/io/qfileinfo/main.cpp b/tests/benchmarks/corelib/io/qfileinfo/main.cpp
index 025787f69f..b272bda692 100644
--- a/tests/benchmarks/corelib/io/qfileinfo/main.cpp
+++ b/tests/benchmarks/corelib/io/qfileinfo/main.cpp
@@ -43,15 +43,20 @@
#include <QtTest/QtTest>
#include <QtCore/QCoreApplication>
#include <QtCore/QFileInfo>
+#include <QtCore/QFile>
#include "private/qfsfileengine_p.h"
+#include "../../../../shared/filesystem.h"
class qfileinfo : public QObject
{
Q_OBJECT
private slots:
void canonicalFileNamePerformance();
-
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+ void symLinkTargetPerformanceLNK();
+ void symLinkTargetPerformanceMounpoint();
+#endif
void initTestCase();
void cleanupTestCase();
public:
@@ -78,6 +83,43 @@ void qfileinfo::canonicalFileNamePerformance()
}
}
+#if defined(Q_OS_WIN) && !defined(Q_OS_WINCE)
+void qfileinfo::symLinkTargetPerformanceLNK()
+{
+ QVERIFY(QFile::link("file","link.lnk"));
+ QFileInfo info("link.lnk");
+ info.setCaching(false);
+ QVERIFY(info.isSymLink());
+ QString linkTarget;
+ QBENCHMARK {
+ for(int i=0; i<100; i++)
+ linkTarget = info.readLink();
+ }
+ QVERIFY(QFile::remove("link.lnk"));
+}
+
+void qfileinfo::symLinkTargetPerformanceMounpoint()
+{
+ wchar_t buffer[MAX_PATH];
+ QString rootPath = QDir::toNativeSeparators(QDir::rootPath());
+ QVERIFY(GetVolumeNameForVolumeMountPointW(rootPath.utf16(), buffer, MAX_PATH));
+ QString rootVolume = QString::fromWCharArray(buffer);
+ QString mountpoint = "mountpoint";
+ rootVolume.replace("\\\\?\\","\\??\\");
+ FileSystem::createNtfsJunction(rootVolume, mountpoint);
+
+ QFileInfo info(mountpoint);
+ info.setCaching(false);
+ QVERIFY(info.isSymLink());
+ QString linkTarget;
+ QBENCHMARK {
+ for(int i=0; i<100; i++)
+ linkTarget = info.readLink();
+ }
+ QVERIFY(QDir().rmdir(mountpoint));
+}
+#endif
+
QTEST_MAIN(qfileinfo)
#include "main.moc"
diff --git a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp
index 36399af15a..ebeea84d5a 100644
--- a/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp
+++ b/tests/benchmarks/corelib/kernel/qmetatype/tst_qmetatype.cpp
@@ -71,6 +71,11 @@ private slots:
void isRegisteredBuiltin();
void isRegisteredCustom();
void isRegisteredNotRegistered();
+
+ void constructCoreType_data();
+ void constructCoreType();
+ void constructCoreTypeCopy_data();
+ void constructCoreTypeCopy();
};
tst_QMetaType::tst_QMetaType()
@@ -229,5 +234,52 @@ void tst_QMetaType::isRegisteredNotRegistered()
}
}
+void tst_QMetaType::constructCoreType_data()
+{
+ QTest::addColumn<int>("typeId");
+ for (int i = 0; i <= QMetaType::LastCoreType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+ for (int i = QMetaType::FirstCoreExtType; i <= QMetaType::LastCoreExtType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+ // GUI types are tested in tst_QGuiMetaType.
+}
+
+// Tests how fast QMetaType can default-construct and destroy a Qt
+// core type. The purpose of this benchmark is to measure the overhead
+// of using type id-based creation compared to creating the type
+// directly (i.e. "T *t = new T(); delete t;").
+void tst_QMetaType::constructCoreType()
+{
+ QFETCH(int, typeId);
+ QBENCHMARK {
+ for (int i = 0; i < 100000; ++i) {
+ void *data = QMetaType::construct(typeId, (void *)0);
+ QMetaType::destroy(typeId, data);
+ }
+ }
+}
+
+void tst_QMetaType::constructCoreTypeCopy_data()
+{
+ constructCoreType_data();
+}
+
+// Tests how fast QMetaType can copy-construct and destroy a Qt core
+// type. The purpose of this benchmark is to measure the overhead of
+// using type id-based creation compared to creating the type directly
+// (i.e. "T *t = new T(other); delete t;").
+void tst_QMetaType::constructCoreTypeCopy()
+{
+ QFETCH(int, typeId);
+ QVariant other(typeId, (void *)0);
+ const void *copy = other.constData();
+ QBENCHMARK {
+ for (int i = 0; i < 100000; ++i) {
+ void *data = QMetaType::construct(typeId, copy);
+ QMetaType::destroy(typeId, data);
+ }
+ }
+}
+
QTEST_MAIN(tst_QMetaType)
#include "tst_qmetatype.moc"
diff --git a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp
index 58cec4f408..5e19c1bff3 100644
--- a/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp
+++ b/tests/benchmarks/corelib/kernel/qvariant/tst_qvariant.cpp
@@ -71,6 +71,11 @@ private slots:
void floatVariantValue();
void rectVariantValue();
void stringVariantValue();
+
+ void createCoreType_data();
+ void createCoreType();
+ void createCoreTypeCopy_data();
+ void createCoreTypeCopy();
};
void tst_qvariant::testBound()
@@ -220,6 +225,48 @@ void tst_qvariant::stringVariantValue()
}
}
+void tst_qvariant::createCoreType_data()
+{
+ QTest::addColumn<int>("typeId");
+ for (int i = 0; i <= QMetaType::LastCoreType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+ for (int i = QMetaType::FirstCoreExtType; i <= QMetaType::LastCoreExtType; ++i)
+ QTest::newRow(QMetaType::typeName(i)) << i;
+}
+
+// Tests how fast a Qt core type can be default-constructed by a
+// QVariant. The purpose of this benchmark is to measure the overhead
+// of creating (and destroying) a QVariant compared to creating the
+// type directly.
+void tst_qvariant::createCoreType()
+{
+ QFETCH(int, typeId);
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ QVariant(typeId, (void *)0);
+ }
+}
+
+void tst_qvariant::createCoreTypeCopy_data()
+{
+ createCoreType_data();
+}
+
+// Tests how fast a Qt core type can be copy-constructed by a
+// QVariant. The purpose of this benchmark is to measure the overhead
+// of creating (and destroying) a QVariant compared to creating the
+// type directly.
+void tst_qvariant::createCoreTypeCopy()
+{
+ QFETCH(int, typeId);
+ QVariant other(typeId, (void *)0);
+ const void *copy = other.constData();
+ QBENCHMARK {
+ for (int i = 0; i < ITERATION_COUNT; ++i)
+ QVariant(typeId, copy);
+ }
+}
+
QTEST_MAIN(tst_qvariant)
#include "tst_qvariant.moc"
diff --git a/tests/benchmarks/corelib/thread/qmutex/qmutex.pro b/tests/benchmarks/corelib/thread/qmutex/qmutex.pro
new file mode 100644
index 0000000000..eda2f1132d
--- /dev/null
+++ b/tests/benchmarks/corelib/thread/qmutex/qmutex.pro
@@ -0,0 +1,6 @@
+load(qttest_p4)
+TEMPLATE = app
+TARGET = tst_bench_qmutex
+
+SOURCES += tst_qmutex.cpp
+
diff --git a/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp
new file mode 100644
index 0000000000..fded5085d0
--- /dev/null
+++ b/tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp
@@ -0,0 +1,131 @@
+/****************************************************************************
+**
+** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
+** Contact: Nokia Corporation (qt-info@nokia.com)
+**
+** This file is part of the test suite of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** No Commercial Usage
+** This file contains pre-release code and may not be distributed.
+** You may use this file in accordance with the terms and conditions
+** contained in the Technology Preview License Agreement accompanying
+** this package.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 as published by the Free Software
+** Foundation and appearing in the file LICENSE.LGPL included in the
+** packaging of this file. Please review the following information to
+** ensure the GNU Lesser General Public License version 2.1 requirements
+** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <qtest.h>
+#include <QtCore>
+
+#include <math.h>
+
+//TESTED_FILES=
+
+
+class tst_QMutex : public QObject
+{
+ Q_OBJECT
+
+public:
+ tst_QMutex();
+ virtual ~tst_QMutex();
+
+private slots:
+ void noThread_data();
+ void noThread();
+};
+
+tst_QMutex::tst_QMutex()
+{
+}
+
+tst_QMutex::~tst_QMutex()
+{
+}
+
+void tst_QMutex::noThread_data()
+{
+ QTest::addColumn<int>("t");
+
+ QTest::newRow("noLock") << 1;
+ QTest::newRow("QMutexInline") << 2;
+ QTest::newRow("QMutex") << 3;
+ QTest::newRow("QMutexLocker") << 4;
+}
+
+void tst_QMutex::noThread()
+{
+ volatile int count = 0;
+ const int N = 5000000;
+ QMutex mtx;
+
+ QFETCH(int, t);
+ switch(t) {
+ case 1:
+ QBENCHMARK {
+ count = 0;
+ for (int i = 0; i < N; i++) {
+ count++;
+ }
+ }
+ break;
+ case 2:
+ QBENCHMARK {
+ count = 0;
+ for (int i = 0; i < N; i++) {
+ mtx.lockInline();
+ count++;
+ mtx.unlockInline();
+ }
+ }
+ break;
+ case 3:
+ QBENCHMARK {
+ count = 0;
+ for (int i = 0; i < N; i++) {
+ mtx.lock();
+ count++;
+ mtx.unlock();
+ }
+ }
+ break;
+ case 4:
+ QBENCHMARK {
+ count = 0;
+ for (int i = 0; i < N; i++) {
+ QMutexLocker locker(&mtx);
+ count++;
+ }
+ }
+ break;
+ }
+ QCOMPARE(int(count), N);
+}
+
+QTEST_MAIN(tst_QMutex)
+#include "tst_qmutex.moc"