summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp
diff options
context:
space:
mode:
authorMilian Wolff <milian.wolff@kdab.com>2014-11-05 17:57:51 +0100
committerSean Harmer <sean.harmer@kdab.com>2014-11-14 20:56:02 +0100
commitdc9fb163aee08a8bca854bc2f100b7606a266beb (patch)
treef71317ca7d4e107950951294b63b02717a9d16c4 /tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp
parent8f2fd1b89d87a850198f8123ed30b796fb328023 (diff)
Add benchmark suite for QFrameAllocator.
Results for instr:k perf counter on my machine are: ********* Start testing of tst_QFrameAllocator ********* Config: Using QtTest library 5.5.0, Qt 5.5.0 (x86_64-little_endian-lp64 shared (dynamic) release build; by GCC 4.9.2) PASS : tst_QFrameAllocator::initTestCase() PASS : tst_QFrameAllocator::benchmarkAllocateSmall() RESULT : tst_QFrameAllocator::benchmarkAllocateSmall(): 1,060,442 instructions per iteration (total: 1,060,442, iterations: 1) PASS : tst_QFrameAllocator::benchmarkAllocateBig() RESULT : tst_QFrameAllocator::benchmarkAllocateBig(): 1,145,940 instructions per iteration (total: 1,145,940, iterations: 1) PASS : tst_QFrameAllocator::benchmarkDeallocateSmall() RESULT : tst_QFrameAllocator::benchmarkDeallocateSmall(): 901,579 instructions per iteration (total: 901,579, iterations: 1) PASS : tst_QFrameAllocator::benchmarkDeallocateBig() RESULT : tst_QFrameAllocator::benchmarkDeallocateBig(): 901,579 instructions per iteration (total: 901,579, iterations: 1) PASS : tst_QFrameAllocator::benchmarkAllocateRaw() RESULT : tst_QFrameAllocator::benchmarkAllocateRaw(): 1,067,539 instructions per iteration (total: 1,067,539, iterations: 1) PASS : tst_QFrameAllocator::benchmarkDeallocateRaw() RESULT : tst_QFrameAllocator::benchmarkDeallocateRaw(): 971,701 instructions per iteration (total: 971,701, iterations: 1) PASS : tst_QFrameAllocator::cleanupTestCase() Totals: 8 passed, 0 failed, 0 skipped, 0 blacklisted ********* Finished testing of tst_QFrameAllocator ********* Change-Id: Iae2bcd53d4efcff4b8486b4571dc1d1acfcbc19d Reviewed-by: Paul Lemire <paul.lemire@kdab.com> Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
Diffstat (limited to 'tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp')
-rw-r--r--tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp148
1 files changed, 148 insertions, 0 deletions
diff --git a/tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp b/tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp
new file mode 100644
index 000000000..bcea3a9d7
--- /dev/null
+++ b/tests/benchmarks/core/qframeallocator/tst_bench_qframeallocator.cpp
@@ -0,0 +1,148 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Klaralvdalens Datakonsult AB (KDAB).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the Qt3D module of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** 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, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, 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.
+**
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include <QObject>
+#include <QtTest/QtTest>
+
+#include <Qt3DCore/QFrameAllocator>
+
+using namespace Qt3D;
+
+class tst_QFrameAllocator : public QObject
+{
+ Q_OBJECT
+
+private Q_SLOTS:
+ void benchmarkAllocateSmall();
+ void benchmarkAllocateBig();
+ void benchmarkDeallocateSmall();
+ void benchmarkDeallocateBig();
+ void benchmarkAllocateRaw();
+ void benchmarkDeallocateRaw();
+};
+
+namespace {
+template<uint Size>
+struct Object {
+ char data[Size];
+};
+
+template<uint Size>
+void benchmarkAlloc()
+{
+ QFrameAllocator allocator(128, 16, 128);
+ QVector<Object<Size>*> items(10000);
+ QBENCHMARK_ONCE {
+ for (int i = 0; i < items.size(); ++i) {
+ items[i] = allocator.allocate< Object<Size> >();
+ }
+ }
+ foreach (Object<Size>* item, items) {
+ allocator.deallocate(item);
+ }
+}
+
+template<uint Size>
+void benchmarkDealloc()
+{
+ QFrameAllocator allocator(128, 16, 128);
+ QVector<Object<Size>*> items(10000);
+ for (int i = 0; i < items.size(); ++i) {
+ items[i] = allocator.allocate< Object<Size> >();
+ }
+ QBENCHMARK_ONCE {
+ foreach (Object<Size>* item, items) {
+ allocator.deallocate(item);
+ }
+ }
+}
+}
+
+void tst_QFrameAllocator::benchmarkAllocateSmall()
+{
+ benchmarkAlloc<16>();
+}
+
+void tst_QFrameAllocator::benchmarkAllocateBig()
+{
+ benchmarkAlloc<128>();
+}
+
+void tst_QFrameAllocator::benchmarkDeallocateSmall()
+{
+ benchmarkDealloc<16>();
+}
+
+void tst_QFrameAllocator::benchmarkDeallocateBig()
+{
+ benchmarkDealloc<128>();
+}
+
+void tst_QFrameAllocator::benchmarkAllocateRaw()
+{
+ QFrameAllocator allocator(128, 16, 128);
+ QVector<void*> items(10000);
+ QBENCHMARK_ONCE {
+ for (int i = 0; i < items.size(); ++i) {
+ items[i] = allocator.allocateRawMemory(i % 128 + 1);
+ }
+ }
+ for (int i = 0; i < items.size(); ++i) {
+ allocator.deallocateRawMemory(items[i], i % 128 + 1);
+ }
+}
+
+void tst_QFrameAllocator::benchmarkDeallocateRaw()
+{
+ QFrameAllocator allocator(128, 16, 128);
+ QVector<void*> items(10000);
+ for (int i = 0; i < items.size(); ++i) {
+ items[i] = allocator.allocateRawMemory(i % 128 + 1);
+ }
+ QBENCHMARK_ONCE {
+ for (int i = 0; i < items.size(); ++i) {
+ allocator.deallocateRawMemory(items[i], i % 128 + 1);
+ }
+ }
+}
+
+QTEST_APPLESS_MAIN(tst_QFrameAllocator)
+#include "tst_bench_qframeallocator.moc"