QStringList: improve benchmark code

Make the strings in the stringlist-to-be-joined unique, which matches
actual use-cases better than joining a list of identical strings,
especially with QString's implicit sharing, if it's copies of the same
QString, it's sharing the underlying data.

Pick-to: 6.5 6.2 5.15
Task-number: QTBUG-116859
Change-Id: I1da93885e938045322ba8337df5e4e96985f892f
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
(cherry picked from commit e1dcc858b2a0ac2b359cdbf7e07e70c1237daef0)
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
This commit is contained in:
Ahmad Samir 2023-04-08 13:38:49 +02:00
parent 9eaaab7df0
commit e1fe8963a7

View File

@ -43,9 +43,9 @@ private:
QStringList tst_QStringList::populateList(const int count, const QString &unit)
{
QStringList retval;
retval.reserve(count);
for (int i = 0; i < count; ++i)
retval.append(unit);
retval.append(unit + QString::number(i));
return retval;
}
@ -77,20 +77,20 @@ void tst_QStringList::join_data() const
QTest::addColumn<QStringList>("input");
QTest::addColumn<QString>("separator");
QTest::newRow("")
QTest::newRow("100")
<< populateList(100, QLatin1String("unit"))
<< QString();
QTest::newRow("")
QTest::newRow("1000")
<< populateList(1000, QLatin1String("unit"))
<< QString();
QTest::newRow("")
<< populateList(10000, QLatin1String("unit"))
QTest::newRow("10000")
<< populateList(10'000, QLatin1String("unit"))
<< QString();
QTest::newRow("")
<< populateList(100000, QLatin1String("unit"))
QTest::newRow("100000")
<< populateList(100'000, QLatin1String("unit"))
<< QString();
}