From 34a37c95a5130af262854eb7a7ef041908cc7aa8 Mon Sep 17 00:00:00 2001 From: Olivier Goffart Date: Thu, 22 Apr 2010 14:18:45 +0200 Subject: Benchmark for QMutex. This currently only cover the case when there is no contention $ ./tst_bench_qmutex noThread -callgrind ********* Start testing of tst_QMutex ********* Config: Using QTest library 4.7.0, Qt 4.7.0 PASS : tst_QMutex::initTestCase() RESULT : tst_QMutex::noThread():"noLock": 60,000,054 instruction reads per iteration (total: 60,000,054, iterations: 1) RESULT : tst_QMutex::noThread():"QMutexInline": 240,000,057 instruction reads per iteration (total: 240,000,057, iterations: 1) RESULT : tst_QMutex::noThread():"QMutex": 380,000,056 instruction reads per iteration (total: 380,000,056, iterations: 1) RESULT : tst_QMutex::noThread():"QMutexLocker": 240,000,058 instruction reads per iteration (total: 240,000,058, iterations: 1) PASS : tst_QMutex::noThread() PASS : tst_QMutex::cleanupTestCase() Totals: 3 passed, 0 failed, 0 skipped ********* Finished testing of tst_QMutex ********* $ make && ./tst_bench_qmutex noThread ********* Start testing of tst_QMutex ********* Config: Using QTest library 4.7.0, Qt 4.7.0 PASS : tst_QMutex::initTestCase() RESULT : tst_QMutex::noThread():"noLock": 27 msecs per iteration (total: 27, iterations: 1) RESULT : tst_QMutex::noThread():"QMutexInline": 212 msecs per iteration (total: 212, iterations: 1) RESULT : tst_QMutex::noThread():"QMutex": 257 msecs per iteration (total: 257, iterations: 1) RESULT : tst_QMutex::noThread():"QMutexLocker": 212 msecs per iteration (total: 212, iterations: 1) PASS : tst_QMutex::noThread() PASS : tst_QMutex::cleanupTestCase() Totals: 3 passed, 0 failed, 0 skipped ********* Finished testing of tst_QMutex ********* --- tests/benchmarks/corelib/thread/qmutex/qmutex.pro | 6 + .../corelib/thread/qmutex/tst_qmutex.cpp | 131 +++++++++++++++++++++ 2 files changed, 137 insertions(+) create mode 100644 tests/benchmarks/corelib/thread/qmutex/qmutex.pro create mode 100644 tests/benchmarks/corelib/thread/qmutex/tst_qmutex.cpp diff --git a/tests/benchmarks/corelib/thread/qmutex/qmutex.pro b/tests/benchmarks/corelib/thread/qmutex/qmutex.pro new file mode 100644 index 0000000..eda2f11 --- /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 0000000..fded508 --- /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 +#include + +#include + +//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("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" -- cgit v0.12