Benchmarks: port Q_FOREACH to ranged-for
Simple cases, all local const containers. tst_QHash: rename the template parameter to "Str". My eyes saw "QList<String>", but my brain somehow assumed QList<*Q*String>. You could argue that I am a bit slow, but it has tricked someone else in code review, so just rename it for the sake of clarity. Drive-by, remove braces from one-line for-loop-block. Task-number: QTBUG-115839 Change-Id: Ia1a56bea7b931efb377ba8c04ee8933561abf341 Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
parent
cdcfaf796e
commit
db5163dca9
@ -1,8 +1,6 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
// Copyright (C) 2016 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||||
|
|
||||||
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
|
|
||||||
|
|
||||||
#include <QTest>
|
#include <QTest>
|
||||||
#include <QDirIterator>
|
#include <QDirIterator>
|
||||||
|
|
||||||
@ -42,8 +40,8 @@ private slots:
|
|||||||
{
|
{
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
|
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
|
||||||
QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted);
|
const QFileInfoList fileInfoList = testdir.entryInfoList(QDir::Files, QDir::Unsorted);
|
||||||
foreach (const QFileInfo &fileInfo, fileInfoList) {
|
for (const QFileInfo &fileInfo : fileInfoList) {
|
||||||
fileInfo.isDir();
|
fileInfo.isDir();
|
||||||
fileInfo.size();
|
fileInfo.size();
|
||||||
}
|
}
|
||||||
@ -66,10 +64,9 @@ private slots:
|
|||||||
{
|
{
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
|
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
|
||||||
QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted);
|
const QFileInfoList fileInfoList = testdir.entryInfoList(QDir::NoFilter, QDir::Unsorted);
|
||||||
foreach (const QFileInfo &fileInfo, fileInfoList) {
|
for (const QFileInfo &fileInfo : fileInfoList)
|
||||||
fileInfo.size();
|
fileInfo.size();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void sizeSpeedWithoutFilterIterator()
|
void sizeSpeedWithoutFilterIterator()
|
||||||
@ -90,8 +87,8 @@ private slots:
|
|||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
|
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
|
||||||
testdir.setSorting(QDir::Unsorted);
|
testdir.setSorting(QDir::Unsorted);
|
||||||
QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted);
|
const QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted);
|
||||||
foreach (const QString &filename, fileList) {
|
for (const QString &filename : fileList) {
|
||||||
QFileInfo fileInfo(filename);
|
QFileInfo fileInfo(filename);
|
||||||
fileInfo.size();
|
fileInfo.size();
|
||||||
}
|
}
|
||||||
@ -104,10 +101,9 @@ private slots:
|
|||||||
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
|
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
|
||||||
testdir.setSorting(QDir::Unsorted);
|
testdir.setSorting(QDir::Unsorted);
|
||||||
testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
|
testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
|
||||||
QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted);
|
const QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Unsorted);
|
||||||
foreach (const QString &filename, fileList) {
|
for (const QString &filename : fileList)
|
||||||
Q_UNUSED(filename);
|
Q_UNUSED(filename);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
void iDontWantAnyStatIterator()
|
void iDontWantAnyStatIterator()
|
||||||
@ -126,10 +122,9 @@ private slots:
|
|||||||
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
|
QDir testdir(QDir::tempPath() + QLatin1String("/test_speed"));
|
||||||
testdir.setSorting(QDir::Time);
|
testdir.setSorting(QDir::Time);
|
||||||
testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
|
testdir.setFilter(QDir::AllEntries | QDir::System | QDir::Hidden);
|
||||||
QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Time);
|
const QStringList fileList = testdir.entryList(QDir::NoFilter, QDir::Time);
|
||||||
foreach (const QString &filename, fileList) {
|
for (const QString &filename : fileList)
|
||||||
Q_UNUSED(filename);
|
Q_UNUSED(filename);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// Copyright (C) 2016 Intel Corporation.
|
// Copyright (C) 2016 Intel Corporation.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||||
|
|
||||||
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
|
|
||||||
|
|
||||||
#include "tst_bench_qhash.h"
|
#include "tst_bench_qhash.h"
|
||||||
|
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
@ -84,7 +82,7 @@ void tst_QHash::initTestCase()
|
|||||||
uuids.reserve(smallFilePaths.size());
|
uuids.reserve(smallFilePaths.size());
|
||||||
longstrings.reserve(smallFilePaths.size());
|
longstrings.reserve(smallFilePaths.size());
|
||||||
|
|
||||||
foreach (const QString &path, smallFilePaths)
|
for (const QString &path : std::as_const(smallFilePaths))
|
||||||
uuids.append(QUuid::createUuidV5(ns, path).toString());
|
uuids.append(QUuid::createUuidV5(ns, path).toString());
|
||||||
for (qsizetype i = 0; i < uuids.size(); ++i)
|
for (qsizetype i = 0; i < uuids.size(); ++i)
|
||||||
longstrings.append(uuids.at(i).repeated(8));
|
longstrings.append(uuids.at(i).repeated(8));
|
||||||
@ -133,13 +131,14 @@ void tst_QHash::data()
|
|||||||
QTest::newRow("numbers") << numbers;
|
QTest::newRow("numbers") << numbers;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename String> void tst_QHash::qhash_template()
|
template <typename Str> void tst_QHash::qhash_template()
|
||||||
{
|
{
|
||||||
QFETCH(QStringList, items);
|
QFETCH(const QStringList, items);
|
||||||
QHash<String, int> hash;
|
QHash<Str, int> hash;
|
||||||
|
|
||||||
QList<String> realitems;
|
QList<Str> realitems;
|
||||||
foreach (const QString &s, items)
|
realitems.reserve(items.size());
|
||||||
|
for (const QString &s : items)
|
||||||
realitems.append(s);
|
realitems.append(s);
|
||||||
|
|
||||||
QBENCHMARK {
|
QBENCHMARK {
|
||||||
@ -149,18 +148,18 @@ template <typename String> void tst_QHash::qhash_template()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename String, size_t Seed> void tst_QHash::hashing_template()
|
template <typename Str, size_t Seed> void tst_QHash::hashing_template()
|
||||||
{
|
{
|
||||||
// just the hashing function
|
// just the hashing function
|
||||||
QFETCH(QStringList, items);
|
QFETCH(const QStringList, items);
|
||||||
|
|
||||||
QList<String> realitems;
|
QList<Str> realitems;
|
||||||
realitems.reserve(items.size());
|
realitems.reserve(items.size());
|
||||||
foreach (const QString &s, items) {
|
for (const QString &s : items) {
|
||||||
if constexpr (std::is_same_v<QString::value_type, typename String::value_type>) {
|
if constexpr (std::is_same_v<QString::value_type, typename Str::value_type>) {
|
||||||
realitems.append(s);
|
realitems.append(s);
|
||||||
} else if constexpr (sizeof(typename String::value_type) == 1) {
|
} else if constexpr (sizeof(typename Str::value_type) == 1) {
|
||||||
realitems.append(String(s.toLatin1()));
|
realitems.append(Str(s.toLatin1()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,8 +2,6 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
|
||||||
// This file contains benchmarks for QRect/QRectF functions.
|
// This file contains benchmarks for QRect/QRectF functions.
|
||||||
|
|
||||||
#undef QT_NO_FOREACH // this file contains unported legacy Q_FOREACH uses
|
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <qtest.h>
|
#include <qtest.h>
|
||||||
|
|
||||||
@ -79,8 +77,8 @@ static void addRectRectData(bool includeProperArg = false)
|
|||||||
if (includeProperArg)
|
if (includeProperArg)
|
||||||
QTest::addColumn<bool>("proper");
|
QTest::addColumn<bool>("proper");
|
||||||
for (int i = 0; i < (includeProperArg ? 2 : 1); ++i) {
|
for (int i = 0; i < (includeProperArg ? 2 : 1); ++i) {
|
||||||
QList<RectRectCombination> combinations = createRectRectCombinations();
|
const QList<RectRectCombination> combinations = createRectRectCombinations();
|
||||||
foreach (RectRectCombination c, combinations) {
|
for (const RectRectCombination &c : combinations) {
|
||||||
QTestData &testData = QTest::newRow(c.tag.toLatin1().data());
|
QTestData &testData = QTest::newRow(c.tag.toLatin1().data());
|
||||||
QRectF r1(c.x1, c.y1, c.w1, c.h1);
|
QRectF r1(c.x1, c.y1, c.w1, c.h1);
|
||||||
QRectF r2(c.x2, c.y2, c.w2, c.h2);
|
QRectF r2(c.x2, c.y2, c.w2, c.h2);
|
||||||
@ -124,8 +122,8 @@ static void addRectPointData(bool includeProperArg = false)
|
|||||||
if (includeProperArg)
|
if (includeProperArg)
|
||||||
QTest::addColumn<bool>("proper");
|
QTest::addColumn<bool>("proper");
|
||||||
for (int i = 0; i < (includeProperArg ? 2 : 1); ++i) {
|
for (int i = 0; i < (includeProperArg ? 2 : 1); ++i) {
|
||||||
QList<RectPointCombination> combinations = createRectPointCombinations();
|
const QList<RectPointCombination> combinations = createRectPointCombinations();
|
||||||
foreach (RectPointCombination c, combinations) {
|
for (const RectPointCombination &c : combinations) {
|
||||||
QTestData &testData = QTest::newRow(c.tag.toLatin1().data());
|
QTestData &testData = QTest::newRow(c.tag.toLatin1().data());
|
||||||
QRectF r(c.x, c.y, c.w, c.h);
|
QRectF r(c.x, c.y, c.w, c.h);
|
||||||
QPointF p(c.px, c.py);
|
QPointF p(c.px, c.py);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user