trollixx

QList Erasing Benchmark

Jul 1st, 2014
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.52 KB | None | 0 0
  1. #include <QObject>
  2. #include <QTest>
  3.  
  4. class QObjectBenchmark : public QObject
  5. {
  6.     Q_OBJECT
  7. private slots:
  8.     void qlist_clean_zero_data();
  9.     void qlist_clean_zero();
  10.  
  11.     void qlist_clean_takeFirst_data();
  12.     void qlist_clean_takeFirst();
  13. };
  14.  
  15. void QObjectBenchmark::qlist_clean_zero_data()
  16. {
  17.     QTest::addColumn<QList<int>>("list");
  18.  
  19.     QList<int> childrenCount;
  20.     childrenCount << 10000 << 100000 << 1000000 << 10000000;
  21.  
  22.     foreach (const int count, childrenCount) {
  23.         QList<int> list;
  24.         for (int i = 0; i < count; ++i)
  25.             list << 0;
  26.         QTest::newRow(qPrintable(QString::number(count) + " children")) << list;
  27.     }
  28. }
  29.  
  30. void QObjectBenchmark::qlist_clean_zero()
  31. {
  32.     QFETCH(QList<int>, list);
  33.     QBENCHMARK {
  34.         for (int i = 0; i < list.count(); ++i) {
  35.             list[i] = 0;
  36.         }
  37.         list.clear();
  38.     }
  39. }
  40.  
  41. void QObjectBenchmark::qlist_clean_takeFirst_data()
  42. {
  43.     QTest::addColumn<QList<int>>("list");
  44.  
  45.     QList<int> childrenCount;
  46.     childrenCount << 10000 << 100000 << 1000000 << 10000000;
  47.  
  48.     foreach (const int count, childrenCount) {
  49.         QList<int> list;
  50.         for (int i = 0; i < count; ++i)
  51.             list << 0;
  52.         QTest::newRow(qPrintable(QString::number(count) + " children")) << list;
  53.     }
  54. }
  55.  
  56. void QObjectBenchmark::qlist_clean_takeFirst()
  57. {
  58.     QFETCH(QList<int>, list);
  59.     QBENCHMARK {
  60.         while (!list.isEmpty())
  61.             list.takeFirst();
  62.     }
  63. }
  64.  
  65. QTEST_MAIN(QObjectBenchmark)
  66.  
  67. #include "main.moc"
Advertisement
Add Comment
Please, Sign In to add comment