summaryrefslogtreecommitdiffstats
path: root/tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp
diff options
context:
space:
mode:
authorSean Harmer <sean.harmer@kdab.com>2014-04-11 09:09:54 +0100
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-04-17 10:40:54 +0200
commitc7ce596dbd3d465c0d0c83b1e020e5eaae32892d (patch)
tree2120ba94170bb4ddf710a4f5a734ba80df497c1a /tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp
parent0fb05e7f6fa326f9e8821e33a0aef1df3c6a55b9 (diff)
Add QCircularBuffer and test
This is different to QtCore's QRingBuffer. QRingBuffer deals with raw bytes with a non-contiguous list of QByteArrays. QCircularBuffer is strongly typed and the data is guaranteed to be stored in a contiguous block of memory. Although the start/end of the buffer may not correspond to the start/end of the block of memory once it has reached capacity and wraps around. Done-with: Andreas Hartmetz and Marc Mutz Change-Id: Id03ad308b13fb359604d19474d892ff22c1e9b93 Reviewed-by: Giuseppe D'Angelo <giuseppe.dangelo@kdab.com>
Diffstat (limited to 'tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp')
-rw-r--r--tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp b/tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp
new file mode 100644
index 000000000..6b408bc47
--- /dev/null
+++ b/tests/benchmarks/core/qcircularbuffer/tst_bench_qcircularbuffer.cpp
@@ -0,0 +1,97 @@
+/****************************************************************************
+**
+** 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/qcircularbuffer.h>
+
+using namespace Qt3D;
+
+class tst_QCircularBuffer : public QObject
+{
+ Q_OBJECT
+private Q_SLOTS:
+ void benchmarkAppend();
+ void benchmarkAt();
+};
+
+void tst_QCircularBuffer::benchmarkAppend()
+{
+ QCircularBuffer<float> c;
+ c.setCapacity(100000);
+ volatile int confuseTheOptimizer = 90000;
+ QBENCHMARK {
+ const int count = confuseTheOptimizer;
+ for (int i = 0; i < count; i++) {
+ c.append(float(i));
+ }
+ }
+ const int count = confuseTheOptimizer;
+ volatile float f;
+ for (int i = 0; i < count; i++) {
+ f = c.at(i);
+ }
+ Q_UNUSED(f);
+}
+
+void tst_QCircularBuffer::benchmarkAt()
+{
+ QCircularBuffer<float> c;
+ c.setCapacity(20000);
+ volatile int confuseTheOptimizer = 90000;
+ const int count = confuseTheOptimizer;
+ for (int i = 0; i < count; i++) {
+ c.append(float(i));
+ }
+ QCOMPARE(c.isLinearised(), false);
+ QBENCHMARK {
+ const int count = c.size();
+ volatile float f;
+ for (int i = 0; i < count; i++) {
+ f = c.at(i);
+ }
+ Q_UNUSED(f);
+ }
+}
+
+QTEST_APPLESS_MAIN(tst_QCircularBuffer)
+#include "tst_bench_qcircularbuffer.moc"