From f61112aa323747714e9a644095b2c5b946bb8179 Mon Sep 17 00:00:00 2001 From: Robin Burchell Date: Fri, 20 Jan 2012 01:27:46 +0200 Subject: Move test files around. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit main.cpp is easier for my muscle memory to remember than qhash_string as it is used by a number of other tests. Change-Id: I044f995d55a4ff1328dde0ae27b6e36a80114c38 Reviewed-by: Richard J. Moore Reviewed-by: João Abecasis --- tests/benchmarks/corelib/tools/qhash/main.cpp | 147 +++++++++++++++++++++ tests/benchmarks/corelib/tools/qhash/main.h | 64 +++++++++ tests/benchmarks/corelib/tools/qhash/outofline.cpp | 2 +- tests/benchmarks/corelib/tools/qhash/qhash.pro | 2 +- .../corelib/tools/qhash/qhash_string.cpp | 147 --------------------- .../benchmarks/corelib/tools/qhash/qhash_string.h | 64 --------- 6 files changed, 213 insertions(+), 213 deletions(-) create mode 100644 tests/benchmarks/corelib/tools/qhash/main.cpp create mode 100644 tests/benchmarks/corelib/tools/qhash/main.h delete mode 100644 tests/benchmarks/corelib/tools/qhash/qhash_string.cpp delete mode 100644 tests/benchmarks/corelib/tools/qhash/qhash_string.h (limited to 'tests/benchmarks/corelib/tools') diff --git a/tests/benchmarks/corelib/tools/qhash/main.cpp b/tests/benchmarks/corelib/tools/qhash/main.cpp new file mode 100644 index 0000000000..463f16393a --- /dev/null +++ b/tests/benchmarks/corelib/tools/qhash/main.cpp @@ -0,0 +1,147 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: http://www.qt-project.org/ +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/* + +//////////////////////////////////////////////////////////////////// + +This benchmark serves as reality check on the idea that hashing the complete +string is a good idea. + + Executive summary: It is not a good idea. + +//////////////////////////////////////////////////////////////////// + +********* Start testing of tst_QHash ********* +Config: Using QTest library 5.0.0, Qt 5.0.0 +PASS : tst_QHash::initTestCase() +RESULT : tst_QHash::qhash_qt4(): + 0.041 msecs per iteration (total: 85, iterations: 2048) +PASS : tst_QHash::qhash_qt4() +RESULT : tst_QHash::qhash_faster(): + 0.0122 msecs per iteration (total: 100, iterations: 8192) +PASS : tst_QHash::qhash_faster() +PASS : tst_QHash::cleanupTestCase() +Totals: 4 passed, 0 failed, 0 skipped + +//////////////////////////////////////////////////////////////////// + +*/ + +#include "main.h" + +#include +#include +#include +#include + +#include + + +class tst_QHash : public QObject +{ + Q_OBJECT + +private slots: + void qhash_qt4(); + void qhash_faster(); + void javaString(); + +private: + QString data(); +}; + +const int N = 1000000; +extern double s; + +///////////////////// QHash ///////////////////// + +QString tst_QHash::data() +{ + QFile file("data.txt"); + file.open(QIODevice::ReadOnly); + return QString::fromLatin1(file.readAll()); +} + +void tst_QHash::qhash_qt4() +{ + QStringList items = data().split(QLatin1Char('\n')); + QHash hash; + + QBENCHMARK { + for (int i = 0, n = items.size(); i != n; ++i) { + hash[items.at(i)] = i; + } + } +} + +void tst_QHash::qhash_faster() +{ + QList items; + foreach (const QString &s, data().split(QLatin1Char('\n'))) + items.append(s); + QHash hash; + + QBENCHMARK { + for (int i = 0, n = items.size(); i != n; ++i) { + hash[items.at(i)] = i; + } + } +} + +void tst_QHash::javaString() +{ + QList items; + foreach (const QString &s, data().split(QLatin1Char('\n'))) + items.append(s); + QHash hash; + + QBENCHMARK { + for (int i = 0, n = items.size(); i != n; ++i) { + hash[items.at(i)] = i; + } + } +} + + +QTEST_MAIN(tst_QHash) + +#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qhash/main.h b/tests/benchmarks/corelib/tools/qhash/main.h new file mode 100644 index 0000000000..cd2dea576f --- /dev/null +++ b/tests/benchmarks/corelib/tools/qhash/main.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: http://www.qt-project.org/ +** +** This file is part of the QtTest module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** GNU Lesser General Public License Usage +** 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. +** +** 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. +** +** Other Usage +** Alternatively, this file may be used in accordance with the terms and +** conditions contained in a signed written agreement between you and Nokia. +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include + +struct String : QString +{ + String() {} + String(const QString &s) : QString(s) {} +}; + +QT_BEGIN_NAMESPACE +uint qHash(const String &); +QT_END_NAMESPACE + + +struct JavaString : QString +{ + JavaString() {} + JavaString(const QString &s) : QString(s) {} +}; + +QT_BEGIN_NAMESPACE +uint qHash(const JavaString &); +QT_END_NAMESPACE + diff --git a/tests/benchmarks/corelib/tools/qhash/outofline.cpp b/tests/benchmarks/corelib/tools/qhash/outofline.cpp index 5f067da2e1..88fd9c144d 100644 --- a/tests/benchmarks/corelib/tools/qhash/outofline.cpp +++ b/tests/benchmarks/corelib/tools/qhash/outofline.cpp @@ -39,7 +39,7 @@ ** ****************************************************************************/ -#include "qhash_string.h" +#include "main.h" static void doHash(const unsigned short *p, uint &h) { diff --git a/tests/benchmarks/corelib/tools/qhash/qhash.pro b/tests/benchmarks/corelib/tools/qhash/qhash.pro index 51d3e7f253..40f661c116 100644 --- a/tests/benchmarks/corelib/tools/qhash/qhash.pro +++ b/tests/benchmarks/corelib/tools/qhash/qhash.pro @@ -1,5 +1,5 @@ TARGET = tst_hash QT = core testlib INCLUDEPATH += . -SOURCES += qhash_string.cpp outofline.cpp +SOURCES += main.cpp outofline.cpp CONFIG += release diff --git a/tests/benchmarks/corelib/tools/qhash/qhash_string.cpp b/tests/benchmarks/corelib/tools/qhash/qhash_string.cpp deleted file mode 100644 index 36e9f41cb7..0000000000 --- a/tests/benchmarks/corelib/tools/qhash/qhash_string.cpp +++ /dev/null @@ -1,147 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: http://www.qt-project.org/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -/* - -//////////////////////////////////////////////////////////////////// - -This benchmark serves as reality check on the idea that hashing the complete -string is a good idea. - - Executive summary: It is not a good idea. - -//////////////////////////////////////////////////////////////////// - -********* Start testing of tst_QHash ********* -Config: Using QTest library 5.0.0, Qt 5.0.0 -PASS : tst_QHash::initTestCase() -RESULT : tst_QHash::qhash_qt4(): - 0.041 msecs per iteration (total: 85, iterations: 2048) -PASS : tst_QHash::qhash_qt4() -RESULT : tst_QHash::qhash_faster(): - 0.0122 msecs per iteration (total: 100, iterations: 8192) -PASS : tst_QHash::qhash_faster() -PASS : tst_QHash::cleanupTestCase() -Totals: 4 passed, 0 failed, 0 skipped - -//////////////////////////////////////////////////////////////////// - -*/ - -#include "qhash_string.h" - -#include -#include -#include -#include - -#include - - -class tst_QHash : public QObject -{ - Q_OBJECT - -private slots: - void qhash_qt4(); - void qhash_faster(); - void javaString(); - -private: - QString data(); -}; - -const int N = 1000000; -extern double s; - -///////////////////// QHash ///////////////////// - -QString tst_QHash::data() -{ - QFile file("data.txt"); - file.open(QIODevice::ReadOnly); - return QString::fromLatin1(file.readAll()); -} - -void tst_QHash::qhash_qt4() -{ - QStringList items = data().split(QLatin1Char('\n')); - QHash hash; - - QBENCHMARK { - for (int i = 0, n = items.size(); i != n; ++i) { - hash[items.at(i)] = i; - } - } -} - -void tst_QHash::qhash_faster() -{ - QList items; - foreach (const QString &s, data().split(QLatin1Char('\n'))) - items.append(s); - QHash hash; - - QBENCHMARK { - for (int i = 0, n = items.size(); i != n; ++i) { - hash[items.at(i)] = i; - } - } -} - -void tst_QHash::javaString() -{ - QList items; - foreach (const QString &s, data().split(QLatin1Char('\n'))) - items.append(s); - QHash hash; - - QBENCHMARK { - for (int i = 0, n = items.size(); i != n; ++i) { - hash[items.at(i)] = i; - } - } -} - - -QTEST_MAIN(tst_QHash) - -#include "qhash_string.moc" diff --git a/tests/benchmarks/corelib/tools/qhash/qhash_string.h b/tests/benchmarks/corelib/tools/qhash/qhash_string.h deleted file mode 100644 index cd2dea576f..0000000000 --- a/tests/benchmarks/corelib/tools/qhash/qhash_string.h +++ /dev/null @@ -1,64 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies). -** All rights reserved. -** Contact: http://www.qt-project.org/ -** -** This file is part of the QtTest module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:LGPL$ -** GNU Lesser General Public License Usage -** 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. -** -** 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. -** -** Other Usage -** Alternatively, this file may be used in accordance with the terms and -** conditions contained in a signed written agreement between you and Nokia. -** -** -** -** -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include - -struct String : QString -{ - String() {} - String(const QString &s) : QString(s) {} -}; - -QT_BEGIN_NAMESPACE -uint qHash(const String &); -QT_END_NAMESPACE - - -struct JavaString : QString -{ - JavaString() {} - JavaString(const QString &s) : QString(s) {} -}; - -QT_BEGIN_NAMESPACE -uint qHash(const JavaString &); -QT_END_NAMESPACE - -- cgit v1.2.3