Paste

URL To paste - | raw - Tue Feb 27 2018 12:06:14 GMT+0000 (Coordinated Universal Time)
#include <QCoreApplication>
#include <QtAlgorithms>
#include <QString>
#include <QElapsedTimer>
#include <QDebug>
#include <vector>
#include <random>
#include <algorithm>

int main(int argc, char *argv[])
{
  // Fill input vector with data.
  std::vector<QString> inputData;
  for (int i = 0; i < 500000; i++)
  {
    inputData.emplace_back(QString("%1.txt").arg(i));
  }

  // Randomize the vector
  std::random_device rd;
  std::mt19937 g(rd());

  std::shuffle(inputData.begin(), inputData.end(), g);

  {
    // Copies the data in a new vector
    std::vector<QString> data = inputData;
    QElapsedTimer timer;
    timer.start();
    qSort(data);
    qDebug() << QString("qSort took: %1 ms").arg(timer.elapsed());
  }

  {
    // Copies the data in a new vector
    std::vector<QString> data = inputData;
    QElapsedTimer timer;
    timer.start();
    std::sort(data.begin(), data.end());
    qDebug() << QString("std::sort took: %1 ms").arg(timer.elapsed());
  }

  QCoreApplication a(argc, argv);

  return a.exec();
}