From 7c848d093e2ce12528d8af435a6e10bc0e28f1e3 Mon Sep 17 00:00:00 2001 From: Thiago Macieira Date: Mon, 18 May 2009 23:24:03 +0200 Subject: Add a benchmark for QString::operator== Reviewed-By: Bradley T. Hughes --- tests/benchmarks/qstring/main.cpp | 104 +++++++++++++++++++++++++++++++++++ tests/benchmarks/qstring/qstring.pro | 4 ++ 2 files changed, 108 insertions(+) create mode 100644 tests/benchmarks/qstring/main.cpp create mode 100644 tests/benchmarks/qstring/qstring.pro diff --git a/tests/benchmarks/qstring/main.cpp b/tests/benchmarks/qstring/main.cpp new file mode 100644 index 0000000..c7962bd --- /dev/null +++ b/tests/benchmarks/qstring/main.cpp @@ -0,0 +1,104 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (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 qt-sales@nokia.com. +** $QT_END_LICENSE$ +** +****************************************************************************/ +#include +#include + +class tst_QString: public QObject +{ + Q_OBJECT +private slots: + void equals() const; + void equals_data() 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, 64, 64, 64, 64, + 96, 96, 96, 96, 96, 96, 96, 96 // 80 + }, 0 + }; + const QChar *ptr = reinterpret_cast(data.data); + + QTest::addColumn("a"); + QTest::addColumn("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); + + // don't use length > 64, since that crosses a cache line + QTest::newRow("aligned-odd") + << QString::fromRawData(ptr, 63) << QString::fromRawData(ptr + 2, 63); + QTest::newRow("aligned-even") + << QString::fromRawData(ptr, 64) << QString::fromRawData(ptr + 2, 64); + QTest::newRow("unaligned-even") + << QString::fromRawData(ptr, 63) << QString::fromRawData(ptr + 1, 63); + QTest::newRow("unaligned-odd") + << QString::fromRawData(ptr, 64) << QString::fromRawData(ptr + 1, 64); +} + +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..74423e7 --- /dev/null +++ b/tests/benchmarks/qstring/qstring.pro @@ -0,0 +1,4 @@ +load(qttest_p4) +TARGET = tst_qstring +QT -= gui +SOURCES += main.cpp -- cgit v0.12