Skip to content
/ qtbase Public

Commit 796e188

Browse files
committed
QMap: add more negative tests to take() benchmark, bench detach()
Ensure each container size has one non-existing item test. Also, for comparison, add "pure detach" tests with the same sizes as the take() tests. Amends the commit that added the take() benchmark. Pick-to: 6.10 6.8 6.5 Change-Id: I4768be0cc73b03cc56ec4399320d1dbcfec75c9a Reviewed-by: Ivan Solovev <ivan.solovev@qt.io> Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io> (cherry picked from commit 1bdaf02) Reviewed-by: Marc Mutz <marc.mutz@qt.io>
1 parent 12c5a48 commit 796e188

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

tests/benchmarks/corelib/tools/qmap/tst_bench_qmap.cpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ private slots:
4040
void take_data();
4141
void take();
4242

43+
void detach_data();
44+
void detach();
45+
4346
private:
4447
QStringList helloEachWorld(int count);
4548
};
@@ -312,9 +315,11 @@ void tst_QMap::take_data()
312315
QTest::addRow("1 in {0}") << 1 << 1;
313316
QTest::addRow("0 in {0, 1}") << 2 << 0;
314317
QTest::addRow("1 in {0, 1}") << 2 << 1;
318+
QTest::addRow("2 in {0, 1}") << 2 << 2;
315319
QTest::addRow("0 in {0...16}") << 17 << 0;
316320
QTest::addRow("7 in {0...16}") << 17 << 7;
317321
QTest::addRow("16 in {0...16}") << 17 << 16;
322+
QTest::addRow("17 in {0...16}") << 17 << 17;
318323
QTest::addRow("1024 in {0...2047}") << 2048 << 1024;
319324
}
320325

@@ -333,6 +338,28 @@ void tst_QMap::take()
333338
}
334339
}
335340

341+
void tst_QMap::detach_data()
342+
{
343+
QTest::addColumn<int>("size");
344+
345+
for (int sz : {0, 1, 2, 17, 2048})
346+
QTest::addRow("%d", sz) << sz;
347+
}
348+
349+
void tst_QMap::detach()
350+
{
351+
QFETCH(const int, size);
352+
353+
QMap<int, QString> map;
354+
for (int i = 0; i < size; ++i)
355+
map[i] = QString::number(i);
356+
357+
QBENCHMARK {
358+
auto copy = map;
359+
copy.detach();
360+
}
361+
}
362+
336363
QTEST_MAIN(tst_QMap)
337364

338365
#include "tst_bench_qmap.moc"

0 commit comments

Comments
 (0)