mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T202, Ref T189 samples (based on RW's review and discussion)
This commit is contained in:
@@ -53,6 +53,7 @@ int main(int argc, char *argv[])
|
||||
qtout << "6d .. JSON model performance (database vs. own JSON)" << endl;
|
||||
qtout << "6e .. string utils vs.regex" << endl;
|
||||
qtout << "6f .. string concatenation (+=, arg, ..)" << endl;
|
||||
qtout << "6g .. const &QString vs. QStringLiteral" << endl;
|
||||
qtout << "7 .. Algorithms" << endl;
|
||||
qtout << "-----" << endl;
|
||||
qtout << "x .. Bye" << endl;
|
||||
@@ -68,6 +69,7 @@ int main(int argc, char *argv[])
|
||||
else if (s.startsWith("6d")) { CSamplesPerformance::samplesJsonModel(qtout); }
|
||||
else if (s.startsWith("6e")) { CSamplesPerformance::samplesStringUtilsVsRegEx(qtout); }
|
||||
else if (s.startsWith("6f")) { CSamplesPerformance::samplesStringConcat(qtout); }
|
||||
else if (s.startsWith("6g")) { CSamplesPerformance::samplesStringLiteralVsConstQString(qtout); }
|
||||
else if (s.startsWith("7")) { CSamplesAlgorithm::samples(); }
|
||||
else if (s.startsWith("x")) { break; }
|
||||
}
|
||||
|
||||
@@ -181,7 +181,7 @@ namespace BlackSample
|
||||
out << "contains matched " << number << " of " << strList4.size() << " strings in " << ms << "ms" << endl;
|
||||
|
||||
out << "-----------------------------------------------" << endl;
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int CSamplesPerformance::interpolatorScenario(QTextStream &out, int numberOfCallsigns, int numberOfTimes)
|
||||
@@ -239,7 +239,7 @@ namespace BlackSample
|
||||
out << "Split by callsign, by time: " << timer.elapsed() << "ms" << endl;
|
||||
|
||||
out << endl;
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int CSamplesPerformance::samplesJson(QTextStream &out)
|
||||
@@ -272,7 +272,7 @@ namespace BlackSample
|
||||
models.convertFromMemoizedJson(json);
|
||||
out << "Convert 10,000 aircraft models from JSON (memoize): " << timer.elapsed() << "ms" << endl << endl;
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int CSamplesPerformance::samplesJsonModel(QTextStream &out)
|
||||
@@ -306,7 +306,7 @@ namespace BlackSample
|
||||
out << "Read via swift JSON format: " << swiftModels.size() << " models in " << ms << "ms" << endl;
|
||||
|
||||
Q_ASSERT_X(swiftModels.size() == dbModels.size(), Q_FUNC_INFO, "Mismatching container size");
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int CSamplesPerformance::samplesStringUtilsVsRegEx(QTextStream &out)
|
||||
@@ -387,7 +387,7 @@ namespace BlackSample
|
||||
}
|
||||
out << "Split 100,000 line string into list of lines: (QList<QStringRef>) " << timer.elapsed() << "ms" << endl;
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int CSamplesPerformance::samplesStringConcat(QTextStream &out)
|
||||
@@ -470,7 +470,63 @@ namespace BlackSample
|
||||
out << "arg QStringLiteral multiple " << time.elapsed() << "ms" << endl;
|
||||
x.clear();
|
||||
|
||||
return 0;
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int CSamplesPerformance::samplesStringLiteralVsConstQString(QTextStream &out)
|
||||
{
|
||||
const int loop = 1e7;
|
||||
QTime time;
|
||||
QString x;
|
||||
time.start();
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
x = fooString();
|
||||
}
|
||||
out << "by constQString " << time.elapsed() << "ms" << endl;
|
||||
x.clear();
|
||||
|
||||
time.start();
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
x = fooStringLiteral();
|
||||
}
|
||||
out << "by QStringLiteral " << time.elapsed() << "ms" << endl;
|
||||
x.clear();
|
||||
|
||||
time.start();
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
x = QString("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi.");
|
||||
}
|
||||
out << "by QString(\"...\") " << time.elapsed() << "ms" << endl;
|
||||
x.clear();
|
||||
|
||||
time.start();
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
x = QStringLiteral("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi.");
|
||||
}
|
||||
out << "by QStringLiteral(\"...\") " << time.elapsed() << "ms" << endl;
|
||||
x.clear();
|
||||
|
||||
time.start();
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
QStringList foo = generateList();
|
||||
Q_UNUSED(foo.size());
|
||||
}
|
||||
out << "generated list " << time.elapsed() << "ms" << endl;
|
||||
|
||||
time.start();
|
||||
for (int i = 0; i < loop; i++)
|
||||
{
|
||||
QStringList foo = replacedList();
|
||||
Q_UNUSED(foo.size());
|
||||
}
|
||||
out << "replaced list " << time.elapsed() << "ms" << endl;
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
CAircraftSituationList CSamplesPerformance::createSituations(qint64 baseTimeEpoch, int numberOfCallsigns, int numberOfTimes)
|
||||
@@ -518,7 +574,7 @@ namespace BlackSample
|
||||
{
|
||||
if (n < 1) return;
|
||||
CAtcStation atc = CTesting::createStation(1);
|
||||
QList<CCoordinateGeodetic> pos(
|
||||
const QList<CCoordinateGeodetic> pos(
|
||||
{
|
||||
CCoordinateGeodetic(10.0, 10.0, 10.0),
|
||||
CCoordinateGeodetic(20.0, 20.0, 20.0),
|
||||
@@ -567,6 +623,31 @@ namespace BlackSample
|
||||
}
|
||||
}
|
||||
|
||||
const QString &CSamplesPerformance::fooString()
|
||||
{
|
||||
static const QString s("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi.");
|
||||
return s;
|
||||
}
|
||||
|
||||
QString CSamplesPerformance::fooStringLiteral()
|
||||
{
|
||||
return QStringLiteral("Lorem ipsum dolor sit amet, consectetur adipiscing elit. Integer nec odio. Praesent libero. Sed cursus ante dapibus diam. Sed nisi.");
|
||||
}
|
||||
|
||||
QStringList CSamplesPerformance::generateList()
|
||||
{
|
||||
return QStringList({"1", "2", "3", "4"});
|
||||
}
|
||||
|
||||
QStringList CSamplesPerformance::replacedList()
|
||||
{
|
||||
static const QStringList l({"1", "2", "3", "4"});
|
||||
QStringList lc(l);
|
||||
lc[1] = QStringLiteral("6");
|
||||
lc[3] = QStringLiteral("7");
|
||||
return lc;
|
||||
}
|
||||
|
||||
const CAtcStationList &CSamplesPerformance::stations10k()
|
||||
{
|
||||
static const CAtcStationList s = CTesting::createAtcStations(10000, false);
|
||||
|
||||
@@ -44,6 +44,9 @@ namespace BlackSample
|
||||
//! String manipulation (concatenation)
|
||||
static int samplesStringConcat(QTextStream &out);
|
||||
|
||||
//! const QString vs. QStringLiteral
|
||||
static int samplesStringLiteralVsConstQString(QTextStream &out);
|
||||
|
||||
private:
|
||||
static const qint64 DeltaTime = 10;
|
||||
|
||||
@@ -70,6 +73,18 @@ namespace BlackSample
|
||||
|
||||
//! parse coordinates from WGS
|
||||
static void parseWgs(int times);
|
||||
|
||||
//! String as reference
|
||||
static const QString &fooString();
|
||||
|
||||
//! String as reference
|
||||
static QString fooStringLiteral();
|
||||
|
||||
//! String list generated
|
||||
static QStringList generateList();
|
||||
|
||||
//! String list generated
|
||||
static QStringList replacedList();
|
||||
};
|
||||
} // namespace
|
||||
|
||||
|
||||
Reference in New Issue
Block a user