mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-04-26 10:45:37 +08:00
Added string concatenation samples
This commit is contained in:
committed by
Mathew Sutcliffe
parent
265b6d33f0
commit
5420aee195
@@ -53,6 +53,7 @@ int main(int argc, char *argv[])
|
|||||||
qtout << "6e .. JSON performance" << endl;
|
qtout << "6e .. JSON performance" << endl;
|
||||||
qtout << "6f .. JSON model performance (database vs. own JSON)" << endl;
|
qtout << "6f .. JSON model performance (database vs. own JSON)" << endl;
|
||||||
qtout << "6g .. string utils vs.regex" << endl;
|
qtout << "6g .. string utils vs.regex" << endl;
|
||||||
|
qtout << "6h .. string concatenation (+=, arg, ..)" << endl;
|
||||||
qtout << "7 .. Algorithms" << endl;
|
qtout << "7 .. Algorithms" << endl;
|
||||||
qtout << "-----" << endl;
|
qtout << "-----" << endl;
|
||||||
qtout << "x .. Bye" << endl;
|
qtout << "x .. Bye" << endl;
|
||||||
@@ -68,7 +69,8 @@ int main(int argc, char *argv[])
|
|||||||
else if (s.startsWith("6d")) { CSamplesPerformance::interpolatorScenario(qtout, 40, 20); }
|
else if (s.startsWith("6d")) { CSamplesPerformance::interpolatorScenario(qtout, 40, 20); }
|
||||||
else if (s.startsWith("6e")) { CSamplesPerformance::samplesJson(qtout); }
|
else if (s.startsWith("6e")) { CSamplesPerformance::samplesJson(qtout); }
|
||||||
else if (s.startsWith("6f")) { CSamplesPerformance::samplesJsonModel(qtout); }
|
else if (s.startsWith("6f")) { CSamplesPerformance::samplesJsonModel(qtout); }
|
||||||
else if (s.startsWith("6g")) { CSamplesPerformance::samplesString(qtout); }
|
else if (s.startsWith("6g")) { CSamplesPerformance::samplesStringUtilsVsRegEx(qtout); }
|
||||||
|
else if (s.startsWith("6h")) { CSamplesPerformance::samplesStringConcat(qtout); }
|
||||||
else if (s.startsWith("7")) { CSamplesAlgorithm::samples(); }
|
else if (s.startsWith("7")) { CSamplesAlgorithm::samples(); }
|
||||||
else if (s.startsWith("x")) { break; }
|
else if (s.startsWith("x")) { break; }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,6 +36,7 @@
|
|||||||
#include <QRegularExpressionMatch>
|
#include <QRegularExpressionMatch>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
|
#include <QStringBuilder>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QTime>
|
#include <QTime>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
@@ -402,7 +403,7 @@ namespace BlackSample
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int CSamplesPerformance::samplesString(QTextStream &out)
|
int CSamplesPerformance::samplesStringUtilsVsRegEx(QTextStream &out)
|
||||||
{
|
{
|
||||||
QTime timer;
|
QTime timer;
|
||||||
static const QString chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~_-=+!\"@#$%^&*()[]{} \t;:\\/?,.<>";
|
static const QString chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789~_-=+!\"@#$%^&*()[]{} \t;:\\/?,.<>";
|
||||||
@@ -483,6 +484,89 @@ namespace BlackSample
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int CSamplesPerformance::samplesStringConcat(QTextStream &out)
|
||||||
|
{
|
||||||
|
const int loop = 250000;
|
||||||
|
QString x;
|
||||||
|
const QString x1 = "11-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const QString x2 = "22-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const QString x3 = "33-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const QString x4 = "44-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const QString x5 = "55-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const QString x6 = "66-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const QString x7 = "77-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const QString x8 = "88-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
const QString x9 = "99-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
|
||||||
|
QTime time;
|
||||||
|
time.start();
|
||||||
|
for (int i = 0; i < loop; i++)
|
||||||
|
{
|
||||||
|
x += "12-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
||||||
|
}
|
||||||
|
out << "+= String " << time.elapsed() << "ms" << endl;
|
||||||
|
x.clear();
|
||||||
|
|
||||||
|
time.start();
|
||||||
|
for (int i = 0; i < loop; i++)
|
||||||
|
{
|
||||||
|
x += QLatin1String("12-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
|
}
|
||||||
|
out << "+= QLatin1String " << time.elapsed() << "ms" << endl;
|
||||||
|
x.clear();
|
||||||
|
|
||||||
|
time.start();
|
||||||
|
for (int i = 0; i < loop; i++)
|
||||||
|
{
|
||||||
|
x += QStringLiteral("12-1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
|
||||||
|
}
|
||||||
|
out << "+= QStringLiteral " << time.elapsed() << "ms" << endl;
|
||||||
|
x.clear();
|
||||||
|
|
||||||
|
time.start();
|
||||||
|
for (int i = 0; i < loop; i++)
|
||||||
|
{
|
||||||
|
x = x1 + x2 + x3 + x4 + x5 + x6 + x7 + x8 + x9;
|
||||||
|
}
|
||||||
|
out << "+ String multiple " << time.elapsed() << "ms" << endl;
|
||||||
|
x.clear();
|
||||||
|
|
||||||
|
time.start();
|
||||||
|
for (int i = 0; i < loop; i++)
|
||||||
|
{
|
||||||
|
x = x1 % x2 % x3 % x4 % x5 % x6 % x7 % x8 % x9;
|
||||||
|
}
|
||||||
|
out << "% String multiple " << time.elapsed() << "ms" << endl;
|
||||||
|
x.clear();
|
||||||
|
|
||||||
|
time.start();
|
||||||
|
for (int i = 0; i < loop; i++)
|
||||||
|
{
|
||||||
|
x = x.append(x1).append(x2).append(x3).append(x4).append(x5).append(x6).append(x7).append(x8).append(x9);
|
||||||
|
}
|
||||||
|
out << "append String multiple " << time.elapsed() << "ms" << endl;
|
||||||
|
x.clear();
|
||||||
|
|
||||||
|
static const QString xArgString("%1 %2 %3 %4 %5 %6 %7 %8 %9");
|
||||||
|
time.start();
|
||||||
|
for (int i = 0; i < loop; i++)
|
||||||
|
{
|
||||||
|
x = xArgString.arg(x1, x2, x3, x4, x5, x6, x7, x8, x9);
|
||||||
|
}
|
||||||
|
out << "arg String multiple " << time.elapsed() << "ms" << endl;
|
||||||
|
x.clear();
|
||||||
|
|
||||||
|
time.start();
|
||||||
|
for (int i = 0; i < loop; i++)
|
||||||
|
{
|
||||||
|
x = QStringLiteral("%1 %2 %3 %4 %5 %6 %7 %8 %9").arg(x1, x2, x3, x4, x5, x6, x7, x8, x9);
|
||||||
|
}
|
||||||
|
out << "arg QStringLiteral multiple " << time.elapsed() << "ms" << endl;
|
||||||
|
x.clear();
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
CAircraftSituationList CSamplesPerformance::createSituations(qint64 baseTimeEpoch, int numberOfCallsigns, int numberOfTimes)
|
CAircraftSituationList CSamplesPerformance::createSituations(qint64 baseTimeEpoch, int numberOfCallsigns, int numberOfTimes)
|
||||||
{
|
{
|
||||||
CAircraftSituationList situations;
|
CAircraftSituationList situations;
|
||||||
@@ -523,5 +607,4 @@ namespace BlackSample
|
|||||||
}
|
}
|
||||||
return models;
|
return models;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|||||||
@@ -42,8 +42,11 @@ namespace BlackSample
|
|||||||
//! JSON loading (database vs. own format
|
//! JSON loading (database vs. own format
|
||||||
static int samplesJsonModel(QTextStream &out);
|
static int samplesJsonModel(QTextStream &out);
|
||||||
|
|
||||||
//! String manipulation
|
//! String manipulation (inserter)
|
||||||
static int samplesString(QTextStream &out);
|
static int samplesStringUtilsVsRegEx(QTextStream &out);
|
||||||
|
|
||||||
|
//! String manipulation (concatenation)
|
||||||
|
static int samplesStringConcat(QTextStream &out);
|
||||||
|
|
||||||
//! Situation values for testing
|
//! Situation values for testing
|
||||||
static BlackMisc::Aviation::CAircraftSituationList createSituations(qint64 baseTimeEpoch, int numberOfCallsigns, int numberOfTimes);
|
static BlackMisc::Aviation::CAircraftSituationList createSituations(qint64 baseTimeEpoch, int numberOfCallsigns, int numberOfTimes);
|
||||||
|
|||||||
Reference in New Issue
Block a user