#include <QCoreApplication>#include <QVector>#include <QStringList>#include <QDebug>#include <QRegExp>#include <QElapsedTimer>//#define TS//#define REGEXP//#define FINDQVector<QString> GenerateList(){ QVector<QString> mVec; for (size_t ix = 0; ix < 100000; ++ix) { mVec.push_back(QString("-Y " + QString::number(qrand()) + " +X " + QString::number(qrand()))); } return mVec;}int main(int argc, char *argv[]){ QCoreApplication a(argc, argv); QVector<QString> mVec = GenerateList(); int y_value; int x_value; QElapsedTimer mTimer; mTimer.start();#ifdef TS qDebug() << "TS method"; foreach (const QString &line, mVec) { QStringList mSubLines = line.split(" "); // Handle error. if (mSubLines.size() != 4) continue; // Handle error. if (mSubLines.at(0) != "-Y" || mSubLines.at(2) != "+X") continue;#ifdef DEBUG qDebug() << "First = " << mSubLines.at(1).toInt(); qDebug() << "Second= " << mSubLines.at(3).toInt(); qDebug() << endl;#endif y_value = mSubLines.at(1).toInt(); x_value = mSubLines.at(3).toInt(); }#endif#ifdef REGEXP qDebug() << "RegExp method."; QRegExp mRegExp; mRegExp.setPattern("^\\-Y\\s+(\\d+)\\s+\\+X\\s+(\\d+)$"); foreach (const QString &line, mVec) { // Handle error. if (mRegExp.indexIn(line) != -1) {#ifdef DEBUG qDebug() << "First = " << mRegExp.cap(1).toInt(); qDebug() << "Second= " << mRegExp.cap(2).toInt();#endif y_value = mRegExp.cap(1).toInt(); x_value = mRegExp.cap(2).toInt(); } }#endif#ifdef FIND qDebug() << "Find method."; foreach (const QString &line, mVec) { //Handle error. if (!line.startsWith("-Y ")) continue; int posX = 0; // Handle error. if ((posX = line.indexOf(" +X ")) == -1) continue; // len of "-Y " str. const int yValueStartPos = 3; // Position after Y value. int yValueEndPos = line.indexOf(" ", yValueStartPos); // Handle error. if (yValueEndPos == -1) continue;#ifdef DEBUG // 4 is length of " +X " str. qDebug() << line.mid(yValueStartPos, yValueEndPos - yValueStartPos); qDebug() << line.mid(posX + 4, line.indexOf(" ", posX)); qDebug() << endl;#endif y_value = line.mid(yValueStartPos, yValueEndPos - yValueStartPos).toInt(); x_value = line.mid(posX + 4, line.indexOf(" ", posX)).toInt(); }#endif qDebug() << "Time elapsed = " << mTimer.elapsed(); return a.exec();}