From a9aa206b7b8ac4e69f8c46233b4080e00e845ff5 Mon Sep 17 00:00:00 2001 From: Edward Welbourne Date: Mon, 27 May 2019 19:13:54 +0200 Subject: Move text-related code out of corelib/tools/ to corelib/text/ This includes byte array, string, char, unicode, locale, collation and regular expressions. Change-Id: I8b125fa52c8c513eb57a0f1298b91910e5a0d786 Reviewed-by: Volker Hilsheimer --- tests/benchmarks/corelib/tools/qbytearray/main.cpp | 264 --------- .../corelib/tools/qbytearray/qbytearray.pro | 7 - tests/benchmarks/corelib/tools/qchar/main.cpp | 136 ----- tests/benchmarks/corelib/tools/qchar/qchar.pro | 3 - .../corelib/tools/qhash/paths_small_data.txt | 56 +- tests/benchmarks/corelib/tools/qlocale/main.cpp | 70 --- tests/benchmarks/corelib/tools/qlocale/qlocale.pro | 4 - tests/benchmarks/corelib/tools/qregexp/main.cpp | 615 --------------------- tests/benchmarks/corelib/tools/qregexp/qregexp.pro | 20 - tests/benchmarks/corelib/tools/qregexp/qregexp.qrc | 6 - tests/benchmarks/corelib/tools/qstring/main.cpp | 193 ------- tests/benchmarks/corelib/tools/qstring/qstring.pro | 5 - .../corelib/tools/qstringbuilder/main.cpp | 420 -------------- .../tools/qstringbuilder/qstringbuilder.pro | 11 - .../corelib/tools/qstringlist/.gitignore | 1 - .../benchmarks/corelib/tools/qstringlist/main.cpp | 201 ------- .../corelib/tools/qstringlist/qstringlist.pro | 5 - tests/benchmarks/corelib/tools/tools.pro | 7 - 18 files changed, 30 insertions(+), 1994 deletions(-) delete mode 100644 tests/benchmarks/corelib/tools/qbytearray/main.cpp delete mode 100644 tests/benchmarks/corelib/tools/qbytearray/qbytearray.pro delete mode 100644 tests/benchmarks/corelib/tools/qchar/main.cpp delete mode 100644 tests/benchmarks/corelib/tools/qchar/qchar.pro delete mode 100644 tests/benchmarks/corelib/tools/qlocale/main.cpp delete mode 100644 tests/benchmarks/corelib/tools/qlocale/qlocale.pro delete mode 100644 tests/benchmarks/corelib/tools/qregexp/main.cpp delete mode 100644 tests/benchmarks/corelib/tools/qregexp/qregexp.pro delete mode 100644 tests/benchmarks/corelib/tools/qregexp/qregexp.qrc delete mode 100644 tests/benchmarks/corelib/tools/qstring/main.cpp delete mode 100644 tests/benchmarks/corelib/tools/qstring/qstring.pro delete mode 100644 tests/benchmarks/corelib/tools/qstringbuilder/main.cpp delete mode 100644 tests/benchmarks/corelib/tools/qstringbuilder/qstringbuilder.pro delete mode 100644 tests/benchmarks/corelib/tools/qstringlist/.gitignore delete mode 100644 tests/benchmarks/corelib/tools/qstringlist/main.cpp delete mode 100644 tests/benchmarks/corelib/tools/qstringlist/qstringlist.pro (limited to 'tests/benchmarks/corelib/tools') diff --git a/tests/benchmarks/corelib/tools/qbytearray/main.cpp b/tests/benchmarks/corelib/tools/qbytearray/main.cpp deleted file mode 100644 index e421e7436b..0000000000 --- a/tests/benchmarks/corelib/tools/qbytearray/main.cpp +++ /dev/null @@ -1,264 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Copyright (C) 2016 Intel Corporation. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include -#include - -#include - - -class tst_qbytearray : public QObject -{ - Q_OBJECT - QByteArray sourcecode; -private slots: - void initTestCase(); - void append(); - void append_data(); - - void latin1Uppercasing_qt54(); - void latin1Uppercasing_xlate(); - void latin1Uppercasing_xlate_checked(); - void latin1Uppercasing_category(); - void latin1Uppercasing_bitcheck(); -}; - -void tst_qbytearray::initTestCase() -{ - QFile self(QFINDTESTDATA("main.cpp")); - QVERIFY(self.open(QIODevice::ReadOnly)); - sourcecode = self.readAll(); -} - -void tst_qbytearray::append_data() -{ - QTest::addColumn("size"); - QTest::newRow("1") << int(1); - QTest::newRow("10") << int(10); - QTest::newRow("100") << int(100); - QTest::newRow("1000") << int(1000); - QTest::newRow("10000") << int(10000); - QTest::newRow("100000") << int(100000); - QTest::newRow("1000000") << int(1000000); - QTest::newRow("10000000") << int(10000000); - QTest::newRow("100000000") << int(100000000); -} - -void tst_qbytearray::append() -{ - QFETCH(int, size); - - QByteArray ba; - QBENCHMARK { - QByteArray ba2(size, 'x'); - ba.append(ba2); - ba.clear(); - } -} - -void tst_qbytearray::latin1Uppercasing_qt54() -{ - QByteArray s = sourcecode; - s.detach(); - - // the following was copied from qbytearray.cpp (except for the QBENCHMARK macro): - uchar *p_orig = reinterpret_cast(s.data()); - uchar *e = reinterpret_cast(s.end()); - - QBENCHMARK { - uchar *p = p_orig; - if (p) { - while (p != e) { - *p = QChar::toLower((ushort)*p); - p++; - } - } - } -} - - -/* -#!/usr/bin/perl -l -use feature "unicode_strings" -for (0..255) { - $up = uc(chr($_)); - $up = chr($_) if ord($up) > 0x100 || length $up > 1; - printf "0x%02x,", ord($up); - print "" if ($_ & 0xf) == 0xf; -} -*/ -static const uchar uppercased[256] = { - 0x00,0x01,0x02,0x03,0x04,0x05,0x06,0x07,0x08,0x09,0x0a,0x0b,0x0c,0x0d,0x0e,0x0f, - 0x10,0x11,0x12,0x13,0x14,0x15,0x16,0x17,0x18,0x19,0x1a,0x1b,0x1c,0x1d,0x1e,0x1f, - 0x20,0x21,0x22,0x23,0x24,0x25,0x26,0x27,0x28,0x29,0x2a,0x2b,0x2c,0x2d,0x2e,0x2f, - 0x30,0x31,0x32,0x33,0x34,0x35,0x36,0x37,0x38,0x39,0x3a,0x3b,0x3c,0x3d,0x3e,0x3f, - 0x40,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, - 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x5b,0x5c,0x5d,0x5e,0x5f, - 0x60,0x41,0x42,0x43,0x44,0x45,0x46,0x47,0x48,0x49,0x4a,0x4b,0x4c,0x4d,0x4e,0x4f, - 0x50,0x51,0x52,0x53,0x54,0x55,0x56,0x57,0x58,0x59,0x5a,0x7b,0x7c,0x7d,0x7e,0x7f, - 0x80,0x81,0x82,0x83,0x84,0x85,0x86,0x87,0x88,0x89,0x8a,0x8b,0x8c,0x8d,0x8e,0x8f, - 0x90,0x91,0x92,0x93,0x94,0x95,0x96,0x97,0x98,0x99,0x9a,0x9b,0x9c,0x9d,0x9e,0x9f, - 0xa0,0xa1,0xa2,0xa3,0xa4,0xa5,0xa6,0xa7,0xa8,0xa9,0xaa,0xab,0xac,0xad,0xae,0xaf, - 0xb0,0xb1,0xb2,0xb3,0xb4,0xb5,0xb6,0xb7,0xb8,0xb9,0xba,0xbb,0xbc,0xbd,0xbe,0xbf, - 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, - 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xd7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xdf, - 0xc0,0xc1,0xc2,0xc3,0xc4,0xc5,0xc6,0xc7,0xc8,0xc9,0xca,0xcb,0xcc,0xcd,0xce,0xcf, - 0xd0,0xd1,0xd2,0xd3,0xd4,0xd5,0xd6,0xf7,0xd8,0xd9,0xda,0xdb,0xdc,0xdd,0xde,0xff -}; -void tst_qbytearray::latin1Uppercasing_xlate() -{ - QByteArray output = sourcecode; - output.detach(); - char *dst_orig = output.data(); - const char *src_orig = sourcecode.constBegin(); - const char *end = sourcecode.constEnd(); - QBENCHMARK { - char *dst = dst_orig; - for (const char *src = src_orig; src != end; ++src, ++dst) - *dst = uppercased[uchar(*src)]; - } -} - -void tst_qbytearray::latin1Uppercasing_xlate_checked() -{ - QByteArray output = sourcecode; - output.detach(); - char *dst_orig = output.data(); - const char *src_orig = sourcecode.constBegin(); - const char *end = sourcecode.constEnd(); - QBENCHMARK { - char *dst = dst_orig; - for (const char *src = src_orig; src != end; ++src, ++dst) { - uchar ch = uchar(*src); - uchar converted = uppercased[ch]; - if (ch != converted) - *dst = converted; - } - } -} - -/* -#!/bin/perl -l -use feature "unicode_strings"; -sub categorize($) { - # 'ß' and 'ÿ' are lowercase, but we cannot uppercase them - return 0 if $_[0] == 0xDF || $_[0] == 0xFF; - $ch = chr($_[0]); - return 2 if uc($ch) ne $ch; - return 1 if lc($ch) ne $ch; - return 0; -} -for (0..255) { - printf "%d,", categorize($_); - print "" if ($_ & 0xf) == 0xf; -} -*/ -static const char categories[256] = { - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0, - 0,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,2,2,2,2,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, - 0,0,0,0,0,2,0,0,0,0,0,0,0,0,0,0, - 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1, - 1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,0, - 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2, - 2,2,2,2,2,2,2,0,2,2,2,2,2,2,2,0 -}; - -void tst_qbytearray::latin1Uppercasing_category() -{ - QByteArray output = sourcecode; - output.detach(); - char *dst_orig = output.data(); - const char *src_orig = sourcecode.constBegin(); - const char *end = sourcecode.constEnd(); - QBENCHMARK { - char *dst = dst_orig; - for (const char *src = src_orig; src != end; ++src, ++dst) - *dst = categories[uchar(*src)] == 1 ? *src & ~0x20 : *src; - } -} - -/* -#!/bin/perl -l -use feature "unicode_strings"; -sub categorize($) { - # 'ß' and 'ÿ' are lowercase, but we cannot uppercase them - return 0 if $_[0] == 0xDF || $_[0] == 0xFF; - $ch = chr($_[0]); - return 2 if uc($ch) ne $ch; - return 1 if lc($ch) ne $ch; - return 0; -} -for $row (0..7) { - $val = 0; - for $col (0..31) { - $val |= (1<<$col) - if categorize($row * 31 + $col) == 2; - } - printf "0x%08x,", $val; -} -*/ - -static const quint32 shouldUppercase[8] = { - 0x00000000,0x00000000,0x00000000,0x3ffffff0,0x00000000,0x04000000,0x00000000,0xbfffff80 -}; - -static bool bittest(const quint32 *data, uchar bit) -{ - static const unsigned bitsperelem = sizeof(*data) * CHAR_BIT; - return data[bit / bitsperelem] & (1 << (bit & (bitsperelem - 1))); -} - -void tst_qbytearray::latin1Uppercasing_bitcheck() -{ - QByteArray output = sourcecode; - output.detach(); - char *dst_orig = output.data(); - const char *src_orig = sourcecode.constBegin(); - const char *end = sourcecode.constEnd(); - QBENCHMARK { - char *dst = dst_orig; - for (const char *src = src_orig; src != end; ++src, ++dst) - *dst = bittest(shouldUppercase, *src) ? uchar(*src) & ~0x20 : uchar(*src); - } -} - - -QTEST_MAIN(tst_qbytearray) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qbytearray/qbytearray.pro b/tests/benchmarks/corelib/tools/qbytearray/qbytearray.pro deleted file mode 100644 index cf28b0247f..0000000000 --- a/tests/benchmarks/corelib/tools/qbytearray/qbytearray.pro +++ /dev/null @@ -1,7 +0,0 @@ -TEMPLATE = app -TARGET = tst_bench_qbytearray - -QT = core testlib - -TESTDATA += main.cpp -SOURCES += main.cpp diff --git a/tests/benchmarks/corelib/tools/qchar/main.cpp b/tests/benchmarks/corelib/tools/qchar/main.cpp deleted file mode 100644 index 4dcf86786d..0000000000 --- a/tests/benchmarks/corelib/tools/qchar/main.cpp +++ /dev/null @@ -1,136 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include - -class tst_QChar: public QObject -{ - Q_OBJECT -private slots: - void isUpper_data(); - void isUpper(); - void isLower_data(); - void isLower(); - void isLetter_data(); - void isLetter(); - void isDigit_data(); - void isDigit(); - void isLetterOrNumber_data(); - void isLetterOrNumber(); - void isSpace_data(); - void isSpace(); -}; - -void tst_QChar::isUpper_data() -{ - QTest::addColumn("c"); - - QTest::newRow("k") << QChar('k'); - QTest::newRow("K") << QChar('K'); - QTest::newRow("5") << QChar('5'); - QTest::newRow("\\0") << QChar(); - QTest::newRow("space") << QChar(' '); - QTest::newRow("\\u3C20") << QChar(0x3C20); -} - -void tst_QChar::isUpper() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isUpper(); - } -} - -void tst_QChar::isLower_data() -{ - isUpper_data(); -} - -void tst_QChar::isLower() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isLower(); - } -} - -void tst_QChar::isLetter_data() -{ - isUpper_data(); -} - -void tst_QChar::isLetter() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isLetter(); - } -} - -void tst_QChar::isDigit_data() -{ - isUpper_data(); -} - -void tst_QChar::isDigit() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isDigit(); - } -} - -void tst_QChar::isLetterOrNumber_data() -{ - isUpper_data(); -} - -void tst_QChar::isLetterOrNumber() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isLetterOrNumber(); - } -} - -void tst_QChar::isSpace_data() -{ - isUpper_data(); -} - -void tst_QChar::isSpace() -{ - QFETCH(QChar, c); - QBENCHMARK { - c.isSpace(); - } -} - -QTEST_MAIN(tst_QChar) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qchar/qchar.pro b/tests/benchmarks/corelib/tools/qchar/qchar.pro deleted file mode 100644 index 80a9861f48..0000000000 --- a/tests/benchmarks/corelib/tools/qchar/qchar.pro +++ /dev/null @@ -1,3 +0,0 @@ -TARGET = tst_bench_qchar -QT = core testlib -SOURCES += main.cpp diff --git a/tests/benchmarks/corelib/tools/qhash/paths_small_data.txt b/tests/benchmarks/corelib/tools/qhash/paths_small_data.txt index d5acd28820..662285296f 100644 --- a/tests/benchmarks/corelib/tools/qhash/paths_small_data.txt +++ b/tests/benchmarks/corelib/tools/qhash/paths_small_data.txt @@ -47,13 +47,38 @@ ./codecs/.obj/debug-shared ./.pch ./.pch/debug-shared +./text +./text/text.pro +./text/qregexp +./text/qregexp/qregexp.qrc +./text/qregexp/main.cpp +./text/qregexp/Makefile +./text/qregexp/qregexp.pro +./text/qstringbuilder +./text/qstringbuilder/main.cpp +./text/qstringbuilder/Makefile +./text/qstringbuilder/qstringbuilder.pro +./text/qstring +./text/qstring/generatelist.pl +./text/qstring/data.h +./text/qstring/qstring.pro +./text/qstring/main.cpp +./text/qstring/data.cpp +./text/qstring/Makefile +./text/qstring/utf-8.txt +./text/qstringlist +./text/qstringlist/qstringlist.pro +./text/qstringlist/main.cpp +./text/qstringlist/.gitignore +./text/qstringlist/Makefile +./text/qbytearray +./text/qbytearray/qbytearray.pro +./text/qbytearray/main.cpp +./text/qbytearray/Makefile +./text/.pch +./text/.pch/debug-shared ./tools ./tools/tools.pro -./tools/qregexp -./tools/qregexp/qregexp.qrc -./tools/qregexp/main.cpp -./tools/qregexp/Makefile -./tools/qregexp/qregexp.pro ./tools/qvector ./tools/qvector/tst_vector ./tools/qvector/.pch @@ -72,31 +97,10 @@ ./tools/qvector/qvector.pro ./tools/.pch ./tools/.pch/debug-shared -./tools/qstringbuilder -./tools/qstringbuilder/main.cpp -./tools/qstringbuilder/Makefile -./tools/qstringbuilder/qstringbuilder.pro ./tools/containers-sequential ./tools/containers-sequential/containers-sequential.pro ./tools/containers-sequential/main.cpp ./tools/containers-sequential/Makefile -./tools/qstring -./tools/qstring/generatelist.pl -./tools/qstring/data.h -./tools/qstring/qstring.pro -./tools/qstring/main.cpp -./tools/qstring/data.cpp -./tools/qstring/Makefile -./tools/qstring/utf-8.txt -./tools/qstringlist -./tools/qstringlist/qstringlist.pro -./tools/qstringlist/main.cpp -./tools/qstringlist/.gitignore -./tools/qstringlist/Makefile -./tools/qbytearray -./tools/qbytearray/qbytearray.pro -./tools/qbytearray/main.cpp -./tools/qbytearray/Makefile ./tools/containers-associative ./tools/containers-associative/containers-associative.pro ./tools/containers-associative/main.cpp diff --git a/tests/benchmarks/corelib/tools/qlocale/main.cpp b/tests/benchmarks/corelib/tools/qlocale/main.cpp deleted file mode 100644 index 38d94af143..0000000000 --- a/tests/benchmarks/corelib/tools/qlocale/main.cpp +++ /dev/null @@ -1,70 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the QtCore module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -class tst_QLocale : public QObject -{ - Q_OBJECT - -private Q_SLOTS: - void toUpper_QLocale_1(); - void toUpper_QLocale_2(); - void toUpper_QString(); -}; - -static QString data() -{ - return QStringLiteral("/qt-5/qtbase/tests/benchmarks/corelib/tools/qlocale"); -} - -#define LOOP(s) for (int i = 0; i < 5000; ++i) { s; } - -void tst_QLocale::toUpper_QLocale_1() -{ - QString s = data(); - QBENCHMARK { LOOP(QLocale().toUpper(s)) } -} - -void tst_QLocale::toUpper_QLocale_2() -{ - QString s = data(); - QLocale l; - QBENCHMARK { LOOP(l.toUpper(s)) } -} - -void tst_QLocale::toUpper_QString() -{ - QString s = data(); - QBENCHMARK { LOOP(s.toUpper()) } -} - -QTEST_MAIN(tst_QLocale) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qlocale/qlocale.pro b/tests/benchmarks/corelib/tools/qlocale/qlocale.pro deleted file mode 100644 index e56bbe0341..0000000000 --- a/tests/benchmarks/corelib/tools/qlocale/qlocale.pro +++ /dev/null @@ -1,4 +0,0 @@ -TARGET = tst_bench_qlocale -QT = core testlib - -SOURCES += main.cpp diff --git a/tests/benchmarks/corelib/tools/qregexp/main.cpp b/tests/benchmarks/corelib/tools/qregexp/main.cpp deleted file mode 100644 index 798b23f2b0..0000000000 --- a/tests/benchmarks/corelib/tools/qregexp/main.cpp +++ /dev/null @@ -1,615 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include -#include -#include - -#include -#ifdef HAVE_BOOST -#include -#endif - -#ifdef HAVE_JSC -#include -#include "pcre/pcre.h" -#endif -#define ZLIB_VERSION "1.2.3.4" - -class tst_qregexp : public QObject -{ - Q_OBJECT -public: - tst_qregexp(); -private slots: - void escape_old(); - void escape_old_data() { escape_data(); } - void escape_new1(); - void escape_new1_data() { escape_data(); } - void escape_new2(); - void escape_new2_data() { escape_data(); } - void escape_new3(); - void escape_new3_data() { escape_data(); } - void escape_new4(); - void escape_new4_data() { escape_data(); } -/* - JSC outperforms everything. - Boost is less impressive then expected. - */ - void simpleFind1(); - void rangeReplace1(); - void matchReplace1(); - - void simpleFind2(); - void rangeReplace2(); - void matchReplace2(); - - void simpleFindJSC(); - void rangeReplaceJSC(); - void matchReplaceJSC(); - - void simpleFindBoost(); - void rangeReplaceBoost(); - void matchReplaceBoost(); - -/* those apply an (incorrect) regexp on entire source - (this main.cpp). JSC appears to handle this - (ab)use case best. QRegExp performs extremly bad. - */ - void horribleWrongReplace1(); - void horribleReplace1(); - void horribleReplace2(); - void horribleWrongReplace2(); - void horribleWrongReplaceJSC(); - void horribleReplaceJSC(); - void horribleWrongReplaceBoost(); - void horribleReplaceBoost(); -private: - QString str1; - QString str2; - void escape_data(); -}; - -tst_qregexp::tst_qregexp() - :QObject() - ,str1("We are all happy monkeys") -{ - QFile f(":/main.cpp"); - f.open(QFile::ReadOnly); - str2=f.readAll(); -} - -static void verify(const QString "ed, const QString &expected) -{ - if (quoted != expected) - qDebug() << "ERROR:" << quoted << expected; -} - -void tst_qregexp::escape_data() -{ - QTest::addColumn("pattern"); - QTest::addColumn("expected"); - - QTest::newRow("escape 0") << "Hello world" << "Hello world"; - QTest::newRow("escape 1") << "(Hello world)" << "\\(Hello world\\)"; - { - QString s; - for (int i = 0; i < 10; ++i) - s += "(escape)"; - QTest::newRow("escape 10") << s << QRegExp::escape(s); - } - { - QString s; - for (int i = 0; i < 100; ++i) - s += "(escape)"; - QTest::newRow("escape 100") << s << QRegExp::escape(s); - } -} - -void tst_qregexp::escape_old() -{ - QFETCH(QString, pattern); - QFETCH(QString, expected); - - QBENCHMARK { - static const char meta[] = "$()*+.?[\\]^{|}"; - QString quoted = pattern; - int i = 0; - - while (i < quoted.length()) { - if (strchr(meta, quoted.at(i).toLatin1()) != 0) - quoted.insert(i++, QLatin1Char('\\')); - ++i; - } - - verify(quoted, expected); - } -} - -void tst_qregexp::escape_new1() -{ - QFETCH(QString, pattern); - QFETCH(QString, expected); - - QBENCHMARK { - QString quoted; - const int count = pattern.count(); - quoted.reserve(count * 2); - const QLatin1Char backslash('\\'); - for (int i = 0; i < count; i++) { - switch (pattern.at(i).toLatin1()) { - case '$': - case '(': - case ')': - case '*': - case '+': - case '.': - case '?': - case '[': - case '\\': - case ']': - case '^': - case '{': - case '|': - case '}': - quoted.append(backslash); - } - quoted.append(pattern.at(i)); - } - verify(quoted, expected); - } -} - -void tst_qregexp::escape_new2() -{ - QFETCH(QString, pattern); - QFETCH(QString, expected); - - QBENCHMARK { - int count = pattern.count(); - const QLatin1Char backslash('\\'); - QString quoted(count * 2, backslash); - const QChar *patternData = pattern.data(); - QChar *quotedData = quoted.data(); - int escaped = 0; - for ( ; --count >= 0; ++patternData) { - const QChar c = *patternData; - switch (c.unicode()) { - case '$': - case '(': - case ')': - case '*': - case '+': - case '.': - case '?': - case '[': - case '\\': - case ']': - case '^': - case '{': - case '|': - case '}': - ++escaped; - ++quotedData; - } - *quotedData = c; - ++quotedData; - } - quoted.resize(pattern.size() + escaped); - - verify(quoted, expected); - } -} - -void tst_qregexp::escape_new3() -{ - QFETCH(QString, pattern); - QFETCH(QString, expected); - - QBENCHMARK { - QString quoted; - const int count = pattern.count(); - quoted.reserve(count * 2); - const QLatin1Char backslash('\\'); - for (int i = 0; i < count; i++) { - switch (pattern.at(i).toLatin1()) { - case '$': - case '(': - case ')': - case '*': - case '+': - case '.': - case '?': - case '[': - case '\\': - case ']': - case '^': - case '{': - case '|': - case '}': - quoted += backslash; - } - quoted += pattern.at(i); - } - - verify(quoted, expected); - } -} - - -static inline bool needsEscaping(int c) -{ - switch (c) { - case '$': - case '(': - case ')': - case '*': - case '+': - case '.': - case '?': - case '[': - case '\\': - case ']': - case '^': - case '{': - case '|': - case '}': - return true; - } - return false; -} - -void tst_qregexp::escape_new4() -{ - QFETCH(QString, pattern); - QFETCH(QString, expected); - - QBENCHMARK { - const int n = pattern.size(); - const QChar *patternData = pattern.data(); - // try to prevent copy if no escape is needed - int i = 0; - for (int i = 0; i != n; ++i) { - const QChar c = patternData[i]; - if (needsEscaping(c.unicode())) - break; - } - if (i == n) { - verify(pattern, expected); - // no escaping needed, "return pattern" should be done here. - return; - } - const QLatin1Char backslash('\\'); - QString quoted(n * 2, backslash); - QChar *quotedData = quoted.data(); - for (int j = 0; j != i; ++j) - *quotedData++ = *patternData++; - int escaped = 0; - for (; i != n; ++i) { - const QChar c = *patternData; - if (needsEscaping(c.unicode())) { - ++escaped; - ++quotedData; - } - *quotedData = c; - ++quotedData; - ++patternData; - } - quoted.resize(n + escaped); - verify(quoted, expected); - // "return quoted" - } -} - - -void tst_qregexp::simpleFind1() -{ - int roff; - QRegExp rx("happy"); - rx.setPatternSyntax(QRegExp::RegExp); - QBENCHMARK{ - roff = rx.indexIn(str1); - } - QCOMPARE(roff, 11); -} - -void tst_qregexp::rangeReplace1() -{ - QString r; - QRegExp rx("[a-f]"); - rx.setPatternSyntax(QRegExp::RegExp); - QBENCHMARK{ - r = QString(str1).replace(rx, "-"); - } - QCOMPARE(r, QString("W- -r- -ll h-ppy monk-ys")); -} - -void tst_qregexp::matchReplace1() -{ - QString r; - QRegExp rx("[^a-f]*([a-f]+)[^a-f]*"); - rx.setPatternSyntax(QRegExp::RegExp); - QBENCHMARK{ - r = QString(str1).replace(rx, "\\1"); - } - QCOMPARE(r, QString("eaeaae")); -} - -void tst_qregexp::horribleWrongReplace1() -{ - QString r; - QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*"); - rx.setPatternSyntax(QRegExp::RegExp); - QBENCHMARK{ - r = QString(str2).replace(rx, "\\1.\\2.\\3"); - } - QCOMPARE(r, str2); -} - -void tst_qregexp::horribleReplace1() -{ - QString r; - QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*"); - rx.setPatternSyntax(QRegExp::RegExp); - QBENCHMARK{ - r = QString(str2).replace(rx, "\\1.\\2.\\3"); - } - QCOMPARE(r, QString("1.2.3")); -} - - -void tst_qregexp::simpleFind2() -{ - int roff; - QRegExp rx("happy"); - rx.setPatternSyntax(QRegExp::RegExp2); - QBENCHMARK{ - roff = rx.indexIn(str1); - } - QCOMPARE(roff, 11); -} - -void tst_qregexp::rangeReplace2() -{ - QString r; - QRegExp rx("[a-f]"); - rx.setPatternSyntax(QRegExp::RegExp2); - QBENCHMARK{ - r = QString(str1).replace(rx, "-"); - } - QCOMPARE(r, QString("W- -r- -ll h-ppy monk-ys")); -} - -void tst_qregexp::matchReplace2() -{ - QString r; - QRegExp rx("[^a-f]*([a-f]+)[^a-f]*"); - rx.setPatternSyntax(QRegExp::RegExp2); - QBENCHMARK{ - r = QString(str1).replace(rx, "\\1"); - } - QCOMPARE(r, QString("eaeaae")); -} - -void tst_qregexp::horribleWrongReplace2() -{ - QString r; - QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*"); - rx.setPatternSyntax(QRegExp::RegExp2); - QBENCHMARK{ - r = QString(str2).replace(rx, "\\1.\\2.\\3"); - } - QCOMPARE(r, str2); -} - -void tst_qregexp::horribleReplace2() -{ - QString r; - QRegExp rx(".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*"); - rx.setPatternSyntax(QRegExp::RegExp2); - QBENCHMARK{ - r = QString(str2).replace(rx, "\\1.\\2.\\3"); - } - QCOMPARE(r, QString("1.2.3")); -} -void tst_qregexp::simpleFindJSC() -{ -#ifdef HAVE_JSC - int numr; - const char * errmsg=" "; - QString rxs("happy"); - JSRegExp *rx = jsRegExpCompile(rxs.utf16(), rxs.length(), JSRegExpDoNotIgnoreCase, JSRegExpSingleLine, 0, &errmsg); - QVERIFY(rx != 0); - QString s(str1); - int offsetVector[3]; - QBENCHMARK{ - numr = jsRegExpExecute(rx, s.utf16(), s.length(), 0, offsetVector, 3); - } - jsRegExpFree(rx); - QCOMPARE(numr, 1); - QCOMPARE(offsetVector[0], 11); -#else - QSKIP("JSC is not enabled for this platform"); -#endif -} - -void tst_qregexp::rangeReplaceJSC() -{ -#ifdef HAVE_JSC - QScriptValue r; - QScriptEngine engine; - engine.globalObject().setProperty("s", str1); - QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/[a-f]/g, '-') } )"); - QVERIFY(replaceFunc.isFunction()); - QBENCHMARK{ - r = replaceFunc.call(QScriptValue()); - } - QCOMPARE(r.toString(), QString("W- -r- -ll h-ppy monk-ys")); -#else - QSKIP("JSC is not enabled for this platform"); -#endif -} - -void tst_qregexp::matchReplaceJSC() -{ -#ifdef HAVE_JSC - QScriptValue r; - QScriptEngine engine; - engine.globalObject().setProperty("s", str1); - QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/[^a-f]*([a-f]+)[^a-f]*/g, '$1') } )"); - QVERIFY(replaceFunc.isFunction()); - QBENCHMARK{ - r = replaceFunc.call(QScriptValue()); - } - QCOMPARE(r.toString(), QString("eaeaae")); -#else - QSKIP("JSC is not enabled for this platform"); -#endif -} - -void tst_qregexp::horribleWrongReplaceJSC() -{ -#ifdef HAVE_JSC - QScriptValue r; - QScriptEngine engine; - engine.globalObject().setProperty("s", str2); - QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/.*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*/gm, '$1.$2.$3') } )"); - QVERIFY(replaceFunc.isFunction()); - QBENCHMARK{ - r = replaceFunc.call(QScriptValue()); - } - QCOMPARE(r.toString(), str2); -#else - QSKIP("JSC is not enabled for this platform"); -#endif -} - -void tst_qregexp::horribleReplaceJSC() -{ -#ifdef HAVE_JSC - QScriptValue r; - QScriptEngine engine; - // the m flag doesn't actually work here; dunno - engine.globalObject().setProperty("s", str2.replace('\n', ' ')); - QScriptValue replaceFunc = engine.evaluate("(function() { return s.replace(/.*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*/gm, '$1.$2.$3') } )"); - QVERIFY(replaceFunc.isFunction()); - QBENCHMARK{ - r = replaceFunc.call(QScriptValue()); - } - QCOMPARE(r.toString(), QString("1.2.3")); -#else - QSKIP("JSC is not enabled for this platform"); -#endif -} - -void tst_qregexp::simpleFindBoost() -{ -#ifdef HAVE_BOOST - int roff; - boost::regex rx ("happy", boost::regex_constants::perl); - std::string s = str1.toStdString(); - std::string::const_iterator start, end; - start = s.begin(); - end = s.end(); - boost::match_flag_type flags = boost::match_default; - QBENCHMARK{ - boost::match_results what; - regex_search(start, end, what, rx, flags); - roff = (what[0].first)-start; - } - QCOMPARE(roff, 11); -#else - QSKIP("Boost is not enabled for this platform"); -#endif - -} - -void tst_qregexp::rangeReplaceBoost() -{ -#ifdef HAVE_BOOST - boost::regex pattern ("[a-f]", boost::regex_constants::perl); - std::string s = str1.toStdString(); - std::string r; - QBENCHMARK{ - r = boost::regex_replace (s, pattern, "-"); - } - QCOMPARE(r, std::string("W- -r- -ll h-ppy monk-ys")); -#else - QSKIP("Boost is not enabled for this platform"); -#endif -} - -void tst_qregexp::matchReplaceBoost() -{ -#ifdef HAVE_BOOST - boost::regex pattern ("[^a-f]*([a-f]+)[^a-f]*",boost::regex_constants::perl); - std::string s = str1.toStdString(); - std::string r; - QBENCHMARK{ - r = boost::regex_replace (s, pattern, "$1"); - } - QCOMPARE(r, std::string("eaeaae")); -#else - QSKIP("Boost is not enabled for this platform"); -#endif -} - -void tst_qregexp::horribleWrongReplaceBoost() -{ -#ifdef HAVE_BOOST - boost::regex pattern (".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+)\".*", boost::regex_constants::perl); - std::string s = str2.toStdString(); - std::string r; - QBENCHMARK{ - r = boost::regex_replace (s, pattern, "$1.$2.$3"); - } - QCOMPARE(r, s); -#else - QSKIP("Boost is not enabled for this platform"); -#endif -} - -void tst_qregexp::horribleReplaceBoost() -{ -#ifdef HAVE_BOOST - boost::regex pattern (".*#""define ZLIB_VERSION \"([0-9]+)\\.([0-9]+)\\.([0-9]+).*", boost::regex_constants::perl); - std::string s = str2.toStdString(); - std::string r; - QBENCHMARK{ - r = boost::regex_replace (s, pattern, "$1.$2.$3"); - } - QCOMPARE(r, std::string("1.2.3")); -#else - QSKIP("Boost is not enabled for this platform"); -#endif -} - -QTEST_MAIN(tst_qregexp) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qregexp/qregexp.pro b/tests/benchmarks/corelib/tools/qregexp/qregexp.pro deleted file mode 100644 index f64ae781a2..0000000000 --- a/tests/benchmarks/corelib/tools/qregexp/qregexp.pro +++ /dev/null @@ -1,20 +0,0 @@ -TEMPLATE = app -TARGET = tst_bench_qregexp -QT = core testlib -CONFIG += release exceptions - -SOURCES += main.cpp -RESOURCES += qregexp.qrc - -qtHaveModule(script):!pcre { - DEFINES += HAVE_JSC - QT += script -} - -!qnx { - exists($$[QT_SYSROOT]/usr/include/boost/regex.hpp) { - DEFINES += HAVE_BOOST - LIBS += -lboost_regex - } -} - diff --git a/tests/benchmarks/corelib/tools/qregexp/qregexp.qrc b/tests/benchmarks/corelib/tools/qregexp/qregexp.qrc deleted file mode 100644 index a7fe13c035..0000000000 --- a/tests/benchmarks/corelib/tools/qregexp/qregexp.qrc +++ /dev/null @@ -1,6 +0,0 @@ - - - main.cpp - - - diff --git a/tests/benchmarks/corelib/tools/qstring/main.cpp b/tests/benchmarks/corelib/tools/qstring/main.cpp deleted file mode 100644 index 826a843c10..0000000000 --- a/tests/benchmarks/corelib/tools/qstring/main.cpp +++ /dev/null @@ -1,193 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ -#include -#include -#include - -class tst_QString: public QObject -{ - Q_OBJECT -public: - tst_QString(); -private slots: - void section_regexp_data() { section_data_impl(); } - void section_regexp() { section_impl(); } - void section_regularexpression_data() { section_data_impl(); } - void section_regularexpression() { section_impl(); } - void section_string_data() { section_data_impl(false); } - void section_string() { section_impl(); } - - void toUpper_data(); - void toUpper(); - void toLower_data(); - void toLower(); - void toCaseFolded_data(); - void toCaseFolded(); - -private: - void section_data_impl(bool includeRegExOnly = true); - template void section_impl(); -}; - -tst_QString::tst_QString() -{ -} - -void tst_QString::section_data_impl(bool includeRegExOnly) -{ - QTest::addColumn("s"); - QTest::addColumn("sep"); - QTest::addColumn("isRegExp"); - - QTest::newRow("IPv4") << QStringLiteral("192.168.0.1") << QStringLiteral(".") << false; - QTest::newRow("IPv6") << QStringLiteral("2001:0db8:85a3:0000:0000:8a2e:0370:7334") << QStringLiteral(":") << false; - if (includeRegExOnly) { - QTest::newRow("IPv6-reversed-roles") << QStringLiteral("2001:0db8:85a3:0000:0000:8a2e:0370:7334") << QStringLiteral("\\d+") << true; - QTest::newRow("IPv6-complex") << QStringLiteral("2001:0db8:85a3:0000:0000:8a2e:0370:7334") << QStringLiteral("(\\d+):\\1") << true; - } -} - -template -inline QString escape(const QString &s) -{ return RX::escape(s); } - -template <> -inline QString escape(const QString &s) -{ return s; } - -template -inline void optimize(RX &) {} - -template <> -inline void optimize(QRegularExpression &rx) -{ rx.optimize(); } - -template -void tst_QString::section_impl() -{ - QFETCH(QString, s); - QFETCH(QString, sep); - QFETCH(bool, isRegExp); - - RX rx(isRegExp ? sep : escape(sep)); - optimize(rx); - for (int i = 0; i < 20; ++i) - (void) s.count(rx); // make (s, rx) hot - - QBENCHMARK { - const QString result = s.section(rx, 0, 16); - Q_UNUSED(result); - } -} - -void tst_QString::toUpper_data() -{ - QTest::addColumn("s"); - - QString lowerLatin1(300, QChar('a')); - QString upperLatin1(300, QChar('A')); - - QString lowerDeseret; - { - QString pattern; - pattern += QChar(QChar::highSurrogate(0x10428)); - pattern += QChar(QChar::lowSurrogate(0x10428)); - for (int i = 0; i < 300 / pattern.size(); ++i) - lowerDeseret += pattern; - } - QString upperDeseret; - { - QString pattern; - pattern += QChar(QChar::highSurrogate(0x10400)); - pattern += QChar(QChar::lowSurrogate(0x10400)); - for (int i = 0; i < 300 / pattern.size(); ++i) - upperDeseret += pattern; - } - - QString lowerLigature(600, QChar(0xFB03)); - - QTest::newRow("600") << (lowerLatin1 + lowerLatin1); - QTest::newRow("600") << (upperLatin1 + upperLatin1); - - QTest::newRow("300+300") << (lowerLatin1 + upperLatin1); - QTest::newRow("300+300") << (upperLatin1 + lowerLatin1); - - QTest::newRow("300<10428>") << (lowerDeseret + lowerDeseret); - QTest::newRow("300<10400>") << (upperDeseret + upperDeseret); - - QTest::newRow("150<10428>+150<10400>") << (lowerDeseret + upperDeseret); - QTest::newRow("150<10400>+150<10428>") << (upperDeseret + lowerDeseret); - - QTest::newRow("300a+150<10400>") << (lowerLatin1 + upperDeseret); - QTest::newRow("300a+150<10428>") << (lowerLatin1 + lowerDeseret); - QTest::newRow("300A+150<10400>") << (upperLatin1 + upperDeseret); - QTest::newRow("300A+150<10428>") << (upperLatin1 + lowerDeseret); - - QTest::newRow("600 (ligature)") << lowerLigature; -} - -void tst_QString::toUpper() -{ - QFETCH(QString, s); - - QBENCHMARK { - s.toUpper(); - } -} - -void tst_QString::toLower_data() -{ - toUpper_data(); -} - -void tst_QString::toLower() -{ - QFETCH(QString, s); - - QBENCHMARK { - s.toLower(); - } -} - -void tst_QString::toCaseFolded_data() -{ - toUpper_data(); -} - -void tst_QString::toCaseFolded() -{ - QFETCH(QString, s); - - QBENCHMARK { - s.toCaseFolded(); - } -} - -QTEST_APPLESS_MAIN(tst_QString) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qstring/qstring.pro b/tests/benchmarks/corelib/tools/qstring/qstring.pro deleted file mode 100644 index 9f5e34b915..0000000000 --- a/tests/benchmarks/corelib/tools/qstring/qstring.pro +++ /dev/null @@ -1,5 +0,0 @@ -TARGET = tst_bench_qstring -QT -= gui -QT += core testlib -SOURCES += main.cpp - diff --git a/tests/benchmarks/corelib/tools/qstringbuilder/main.cpp b/tests/benchmarks/corelib/tools/qstringbuilder/main.cpp deleted file mode 100644 index 0de6d33846..0000000000 --- a/tests/benchmarks/corelib/tools/qstringbuilder/main.cpp +++ /dev/null @@ -1,420 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite module of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -// Select one of the scenarios below -#define SCENARIO 1 - -#if SCENARIO == 1 -// this is the "no harm done" version. Only operator% is active, -// with NO_CAST * defined -#define P % -#undef QT_USE_FAST_OPERATOR_PLUS -#undef QT_USE_FAST_CONCATENATION -#define QT_NO_CAST_FROM_ASCII -#define QT_NO_CAST_TO_ASCII -#endif - - -#if SCENARIO == 2 -// this is the "full" version. Operator+ is replaced by a QStringBuilder -// based version -// with NO_CAST * defined -#define P + -#define QT_USE_FAST_OPERATOR_PLUS -#define QT_USE_FAST_CONCATENATION -#define QT_NO_CAST_FROM_ASCII -#define QT_NO_CAST_TO_ASCII -#endif - -#if SCENARIO == 3 -// this is the "no harm done" version. Only operator% is active, -// with NO_CAST * _not_ defined -#define P % -#undef QT_USE_FAST_OPERATOR_PLUS -#undef QT_USE_FAST_CONCATENATION -#undef QT_NO_CAST_FROM_ASCII -#undef QT_NO_CAST_TO_ASCII -#endif - -#if SCENARIO == 4 -// this is the "full" version. Operator+ is replaced by a QStringBuilder -// based version -// with NO_CAST * _not_ defined -#define P + -#define QT_USE_FAST_OPERATOR_PLUS -#define QT_USE_FAST_CONCATENATION -#undef QT_NO_CAST_FROM_ASCII -#undef QT_NO_CAST_TO_ASCII -#endif - - -#include -#include -#include -#include - -#include - -#include - -#define COMPARE(a, b) QCOMPARE(a, b) -//#define COMPARE(a, b) - -#define SEP(s) qDebug() << "\n\n-------- " s " ---------"; - -#define LITERAL "some string literal" - -class tst_qstringbuilder : public QObject -{ - Q_OBJECT - -public: - tst_qstringbuilder() - : l1literal(LITERAL), - l1string(LITERAL), - ba(LITERAL), - string(l1string), - stdstring(LITERAL), - stringref(&string, 2, 10), - achar('c'), - r2(QLatin1String(LITERAL LITERAL)), - r3(QLatin1String(LITERAL LITERAL LITERAL)), - r4(QLatin1String(LITERAL LITERAL LITERAL LITERAL)), - r5(QLatin1String(LITERAL LITERAL LITERAL LITERAL LITERAL)) - {} - - -public: - enum { N = 10000 }; - - int run_traditional() - { - int s = 0; - for (int i = 0; i < N; ++i) { -#if 0 - s += QString(l1string + l1string).size(); - s += QString(l1string + l1string + l1string).size(); - s += QString(l1string + l1string + l1string + l1string).size(); - s += QString(l1string + l1string + l1string + l1string + l1string).size(); -#endif - s += QString(achar + l1string + achar).size(); - } - return s; - } - - int run_builder() - { - int s = 0; - for (int i = 0; i < N; ++i) { -#if 0 - s += QString(l1literal P l1literal).size(); - s += QString(l1literal P l1literal P l1literal).size(); - s += QString(l1literal P l1literal P l1literal P l1literal).size(); - s += QString(l1literal P l1literal P l1literal P l1literal P l1literal).size(); -#endif - s += QString(achar % l1literal % achar).size(); - } - return s; - } - -private slots: - - void separator_0() { - qDebug() << "\nIn each block the QStringBuilder based result appear first " - "(with a 'b_' prefix), QStringBased second ('q_' prefix), std::string " - "last ('s_' prefix)\n"; - } - - void separator_1() { SEP("literal + literal (builder first)"); } - - void b_2_l1literal() { - QBENCHMARK { r = l1literal P l1literal; } - COMPARE(r, r2); - } - #ifndef QT_NO_CAST_FROM_ASCII - void b_l1literal_LITERAL() { - QBENCHMARK { r = l1literal P LITERAL; } - COMPARE(r, r2); - } - #endif - void q_2_l1string() { - QBENCHMARK { r = l1string + l1string; } - COMPARE(r, r2); - } - - - void separator_2() { SEP("2 strings"); } - - void b_2_string() { - QBENCHMARK { r = string P string; } - COMPARE(r, r2); - } - void q_2_string() { - QBENCHMARK { r = string + string; } - COMPARE(r, r2); - } - void s_2_string() { - QBENCHMARK { stdr = stdstring + stdstring; } - COMPARE(stdr, stdstring + stdstring); - } - - - void separator_2c() { SEP("2 string refs"); } - - void b_2_stringref() { - QBENCHMARK { r = stringref % stringref; } - COMPARE(r, QString(stringref.toString() + stringref.toString())); - } - void q_2_stringref() { - QBENCHMARK { r = stringref.toString() + stringref.toString(); } - COMPARE(r, QString(stringref % stringref)); - } - - - void separator_2b() { SEP("3 strings"); } - - void b_3_string() { - QBENCHMARK { r = string P string P string; } - COMPARE(r, r3); - } - void q_3_string() { - QBENCHMARK { r = string + string + string; } - COMPARE(r, r3); - } - void s_3_string() { - QBENCHMARK { stdr = stdstring + stdstring + stdstring; } - COMPARE(stdr, stdstring + stdstring + stdstring); - } - - void separator_2e() { SEP("4 strings"); } - - void b_4_string() { - QBENCHMARK { r = string P string P string P string; } - COMPARE(r, r4); - } - void q_4_string() { - QBENCHMARK { r = string + string + string + string; } - COMPARE(r, r4); - } - void s_4_string() { - QBENCHMARK { stdr = stdstring + stdstring + stdstring + stdstring; } - COMPARE(stdr, stdstring + stdstring + stdstring + stdstring); - } - - - - void separator_2a() { SEP("string + literal (builder first)"); } - - void b_string_l1literal() { - QBENCHMARK { r = string % l1literal; } - COMPARE(r, r2); - } - #ifndef QT_NO_CAST_FROM_ASCII - void b_string_LITERAL() { - QBENCHMARK { r = string P LITERAL; } - COMPARE(r, r2); - } - void b_LITERAL_string() { - QBENCHMARK { r = LITERAL P string; } - COMPARE(r, r2); - } - #endif - void b_string_l1string() { - QBENCHMARK { r = string P l1string; } - COMPARE(r, r2); - } - void q_string_l1literal() { - QBENCHMARK { r = string + l1string; } - COMPARE(r, r2); - } - void q_string_l1string() { - QBENCHMARK { r = string + l1string; } - COMPARE(r, r2); - } - void s_LITERAL_string() { - QBENCHMARK { stdr = LITERAL + stdstring; } - COMPARE(stdr, stdstring + stdstring); - } - - - void separator_3() { SEP("3 literals"); } - - void b_3_l1literal() { - QBENCHMARK { r = l1literal P l1literal P l1literal; } - COMPARE(r, r3); - } - void q_3_l1string() { - QBENCHMARK { r = l1string + l1string + l1string; } - COMPARE(r, r3); - } - void s_3_l1string() { - QBENCHMARK { stdr = stdstring + LITERAL + LITERAL; } - COMPARE(stdr, stdstring + stdstring + stdstring); - } - - - void separator_4() { SEP("4 literals"); } - - void b_4_l1literal() { - QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal; } - COMPARE(r, r4); - } - void q_4_l1string() { - QBENCHMARK { r = l1string + l1string + l1string + l1string; } - COMPARE(r, r4); - } - - - void separator_5() { SEP("5 literals"); } - - void b_5_l1literal() { - QBENCHMARK { r = l1literal P l1literal P l1literal P l1literal P l1literal; } - COMPARE(r, r5); - } - - void q_5_l1string() { - QBENCHMARK { r = l1string + l1string + l1string + l1string + l1string; } - COMPARE(r, r5); - } - - - void separator_6() { SEP("4 chars"); } - - void b_string_4_char() { - QBENCHMARK { r = string + achar + achar + achar + achar; } - COMPARE(r, QString(string P achar P achar P achar P achar)); - } - - void q_string_4_char() { - QBENCHMARK { r = string + achar + achar + achar + achar; } - COMPARE(r, QString(string P achar P achar P achar P achar)); - } - - void s_string_4_char() { - QBENCHMARK { stdr = stdstring + 'c' + 'c' + 'c' + 'c'; } - COMPARE(stdr, stdstring + 'c' + 'c' + 'c' + 'c'); - } - - - void separator_7() { SEP("char + string + char"); } - - void b_char_string_char() { - QBENCHMARK { r = achar + string + achar; } - COMPARE(r, QString(achar P string P achar)); - } - - void q_char_string_char() { - QBENCHMARK { r = achar + string + achar; } - COMPARE(r, QString(achar P string P achar)); - } - - void s_char_string_char() { - QBENCHMARK { stdr = 'c' + stdstring + 'c'; } - COMPARE(stdr, 'c' + stdstring + 'c'); - } - - - void separator_8() { SEP("string.arg"); } - - void b_string_arg() { - const QString pattern = l1string + QString::fromLatin1("%1") + l1string; - QBENCHMARK { r = l1literal P string P l1literal; } - COMPARE(r, r3); - } - - void q_string_arg() { - const QString pattern = l1string + QLatin1String("%1") + l1string; - QBENCHMARK { r = pattern.arg(string); } - COMPARE(r, r3); - } - - void q_bytearray_arg() { - QByteArray result; - QBENCHMARK { result = ba + ba + ba; } - } - - - void separator_9() { SEP("QString::reserve()"); } - - void b_reserve() { - QBENCHMARK { - r.clear(); - r = string P string P string P string; - } - COMPARE(r, r4); - } - void b_reserve_lit() { - QBENCHMARK { - r.clear(); - r = string P l1literal P string P string; - } - COMPARE(r, r4); - } - void s_reserve() { - QBENCHMARK { - r.clear(); - r.reserve(string.size() + string.size() + string.size() + string.size()); - r += string; - r += string; - r += string; - r += string; - } - COMPARE(r, r4); - } - void s_reserve_lit() { - QBENCHMARK { - r.clear(); - //r.reserve(string.size() + qstrlen(l1string.latin1()) - // + string.size() + string.size()); - r.reserve(1024); - r += string; - r += l1string; - r += string; - r += string; - } - COMPARE(r, r4); - } - -private: - const QLatin1String l1literal; - const QLatin1String l1string; - const QByteArray ba; - const QString string; - const std::string stdstring; - const QStringRef stringref; - const QLatin1Char achar; - const QString r2, r3, r4, r5; - - // short cuts for results - QString r; - std::string stdr; -}; - -QTEST_MAIN(tst_qstringbuilder) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qstringbuilder/qstringbuilder.pro b/tests/benchmarks/corelib/tools/qstringbuilder/qstringbuilder.pro deleted file mode 100644 index fa4cbe3c13..0000000000 --- a/tests/benchmarks/corelib/tools/qstringbuilder/qstringbuilder.pro +++ /dev/null @@ -1,11 +0,0 @@ -TEMPLATE = app -TARGET = tst_bench_qstringbuilder - -QMAKE_CXXFLAGS += -g -QMAKE_CFLAGS += -g - -QT = core testlib - -CONFIG += release - -SOURCES += main.cpp diff --git a/tests/benchmarks/corelib/tools/qstringlist/.gitignore b/tests/benchmarks/corelib/tools/qstringlist/.gitignore deleted file mode 100644 index 3e0cdc952f..0000000000 --- a/tests/benchmarks/corelib/tools/qstringlist/.gitignore +++ /dev/null @@ -1 +0,0 @@ -tst_qstringlist diff --git a/tests/benchmarks/corelib/tools/qstringlist/main.cpp b/tests/benchmarks/corelib/tools/qstringlist/main.cpp deleted file mode 100644 index ae355a8b89..0000000000 --- a/tests/benchmarks/corelib/tools/qstringlist/main.cpp +++ /dev/null @@ -1,201 +0,0 @@ -/**************************************************************************** -** -** Copyright (C) 2016 The Qt Company Ltd. -** Contact: https://www.qt.io/licensing/ -** -** This file is part of the test suite of the Qt Toolkit. -** -** $QT_BEGIN_LICENSE:GPL-EXCEPT$ -** 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 The Qt Company. For licensing terms -** and conditions see https://www.qt.io/terms-conditions. For further -** information use the contact form at https://www.qt.io/contact-us. -** -** GNU General Public License Usage -** Alternatively, this file may be used under the terms of the GNU -** General Public License version 3 as published by the Free Software -** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT -** included in the packaging of this file. Please review the following -** information to ensure the GNU General Public License requirements will -** be met: https://www.gnu.org/licenses/gpl-3.0.html. -** -** $QT_END_LICENSE$ -** -****************************************************************************/ - -#include -#include - -#include -#include -#include - -class tst_QStringList: public QObject -{ - Q_OBJECT - -private slots: - void join() const; - void join_data() const; - - void split_qlist_qbytearray() const; - void split_qlist_qbytearray_data() const { return split_data(); } - - void split_data() const; - void split_qlist_qstring() const; - void split_qlist_qstring_data() const { return split_data(); } - - void split_stdvector_stdstring() const; - void split_stdvector_stdstring_data() const { return split_data(); } - - void split_stdvector_stdwstring() const; - void split_stdvector_stdwstring_data() const { return split_data(); } - - void split_stdlist_stdstring() const; - void split_stdlist_stdstring_data() const { return split_data(); } - -private: - static QStringList populateList(const int count, const QString &unit); - static QString populateString(const int count, const QString &unit); -}; - -QStringList tst_QStringList::populateList(const int count, const QString &unit) -{ - QStringList retval; - - for (int i = 0; i < count; ++i) - retval.append(unit); - - return retval; -} - -QString tst_QStringList::populateString(const int count, const QString &unit) -{ - QString retval; - - for (int i = 0; i < count; ++i) { - retval.append(unit); - retval.append(QLatin1Char(':')); - } - - return retval; -} - -void tst_QStringList::join() const -{ - QFETCH(QStringList, input); - QFETCH(QString, separator); - - QBENCHMARK { - input.join(separator); - } -} - -void tst_QStringList::join_data() const -{ - QTest::addColumn("input"); - QTest::addColumn("separator"); - - QTest::newRow("") - << populateList(100, QLatin1String("unit")) - << QString(); - - QTest::newRow("") - << populateList(1000, QLatin1String("unit")) - << QString(); - - QTest::newRow("") - << populateList(10000, QLatin1String("unit")) - << QString(); - - QTest::newRow("") - << populateList(100000, QLatin1String("unit")) - << QString(); -} - -void tst_QStringList::split_data() const -{ - QTest::addColumn("input"); - QString unit = QLatin1String("unit") + QString(100, QLatin1Char('s')); - //QTest::newRow("") << populateString(10, unit); - QTest::newRow("") << populateString(100, unit); - //QTest::newRow("") << populateString(100, unit); - //QTest::newRow("") << populateString(1000, unit); - //QTest::newRow("") << populateString(10000, unit); -} - -void tst_QStringList::split_qlist_qbytearray() const -{ - QFETCH(QString, input); - const char splitChar = ':'; - QByteArray ba = input.toLatin1(); - - QBENCHMARK { - ba.split(splitChar); - } -} - -void tst_QStringList::split_qlist_qstring() const -{ - QFETCH(QString, input); - const QChar splitChar = ':'; - - QBENCHMARK { - input.split(splitChar); - } -} - -void tst_QStringList::split_stdvector_stdstring() const -{ - QFETCH(QString, input); - const char split_char = ':'; - std::string stdinput = input.toStdString(); - - QBENCHMARK { - std::istringstream split(stdinput); - std::vector token; - for (std::string each; - std::getline(split, each, split_char); - token.push_back(each)) - ; - } -} - -void tst_QStringList::split_stdvector_stdwstring() const -{ - QFETCH(QString, input); - const wchar_t split_char = ':'; - std::wstring stdinput = input.toStdWString(); - - QBENCHMARK { - std::wistringstream split(stdinput); - std::vector token; - for (std::wstring each; - std::getline(split, each, split_char); - token.push_back(each)) - ; - } -} - -void tst_QStringList::split_stdlist_stdstring() const -{ - QFETCH(QString, input); - const char split_char = ':'; - std::string stdinput = input.toStdString(); - - QBENCHMARK { - std::istringstream split(stdinput); - std::list token; - for (std::string each; - std::getline(split, each, split_char); - token.push_back(each)) - ; - } -} - -QTEST_MAIN(tst_QStringList) - -#include "main.moc" diff --git a/tests/benchmarks/corelib/tools/qstringlist/qstringlist.pro b/tests/benchmarks/corelib/tools/qstringlist/qstringlist.pro deleted file mode 100644 index 5803e7da0e..0000000000 --- a/tests/benchmarks/corelib/tools/qstringlist/qstringlist.pro +++ /dev/null @@ -1,5 +0,0 @@ -TARGET = tst_bench_qstringlist -CONFIG -= debug -CONFIG += release -QT = core testlib -SOURCES += main.cpp diff --git a/tests/benchmarks/corelib/tools/tools.pro b/tests/benchmarks/corelib/tools/tools.pro index 33cbe00438..b4ee0520a6 100644 --- a/tests/benchmarks/corelib/tools/tools.pro +++ b/tests/benchmarks/corelib/tools/tools.pro @@ -2,19 +2,12 @@ TEMPLATE = subdirs SUBDIRS = \ containers-associative \ containers-sequential \ - qbytearray \ qcontiguouscache \ qcryptographichash \ qlist \ - qlocale \ qmap \ qrect \ qringbuffer \ qstack \ - qstring \ - qstringbuilder \ - qstringlist \ qvector \ qalgorithms - -!*g++*: SUBDIRS -= qstring -- cgit v1.2.3