Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <QObject>
- #include <QTest>
- class QObjectBenchmark : public QObject
- {
- Q_OBJECT
- private slots:
- void qlist_clean_zero_data();
- void qlist_clean_zero();
- void qlist_clean_takeFirst_data();
- void qlist_clean_takeFirst();
- };
- void QObjectBenchmark::qlist_clean_zero_data()
- {
- QTest::addColumn<QList<int>>("list");
- QList<int> childrenCount;
- childrenCount << 10000 << 100000 << 1000000 << 10000000;
- foreach (const int count, childrenCount) {
- QList<int> list;
- for (int i = 0; i < count; ++i)
- list << 0;
- QTest::newRow(qPrintable(QString::number(count) + " children")) << list;
- }
- }
- void QObjectBenchmark::qlist_clean_zero()
- {
- QFETCH(QList<int>, list);
- QBENCHMARK {
- for (int i = 0; i < list.count(); ++i) {
- list[i] = 0;
- }
- list.clear();
- }
- }
- void QObjectBenchmark::qlist_clean_takeFirst_data()
- {
- QTest::addColumn<QList<int>>("list");
- QList<int> childrenCount;
- childrenCount << 10000 << 100000 << 1000000 << 10000000;
- foreach (const int count, childrenCount) {
- QList<int> list;
- for (int i = 0; i < count; ++i)
- list << 0;
- QTest::newRow(qPrintable(QString::number(count) + " children")) << list;
- }
- }
- void QObjectBenchmark::qlist_clean_takeFirst()
- {
- QFETCH(QList<int>, list);
- QBENCHMARK {
- while (!list.isEmpty())
- list.takeFirst();
- }
- }
- QTEST_MAIN(QObjectBenchmark)
- #include "main.moc"
Advertisement
Add Comment
Please, Sign In to add comment