mirror of
https://github.com/swift-project/pilotclient.git
synced 2026-03-22 14:55:36 +08:00
Ref T308, use optimized version in model reader/performance samples
This commit is contained in:
@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
|
||||
else if (s.startsWith("6a")) { CSamplesPerformance::samplesMisc(qtout); }
|
||||
else if (s.startsWith("6b")) { CSamplesPerformance::interpolatorScenario(qtout, 40, 20); }
|
||||
else if (s.startsWith("6c")) { CSamplesPerformance::samplesJson(qtout); }
|
||||
else if (s.startsWith("6d")) { CSamplesPerformance::samplesJsonModel(qtout); }
|
||||
else if (s.startsWith("6d")) { CSamplesPerformance::samplesJsonModelAndLivery(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); }
|
||||
|
||||
@@ -275,26 +275,59 @@ namespace BlackSample
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
||||
int CSamplesPerformance::samplesJsonModel(QTextStream &out)
|
||||
int CSamplesPerformance::samplesJsonModelAndLivery(QTextStream &out)
|
||||
{
|
||||
const QString dir = CDirectoryUtils::staticDbFilesDirectory();
|
||||
const QString file = QDir(dir).filePath("models.json");
|
||||
QFile modelFile(file);
|
||||
Q_ASSERT_X(modelFile.exists(), Q_FUNC_INFO, "Model file does not exist");
|
||||
const QString modelFileName = QDir(dir).filePath("models.json");
|
||||
const QString liveriesFileName = QDir(dir).filePath("liveries.json");
|
||||
|
||||
out << "Load DB JSON file " << modelFile.fileName() << endl;
|
||||
const QString data = CFileUtils::readFileToString(modelFile.fileName());
|
||||
Q_ASSERT_X(!data.isEmpty(), Q_FUNC_INFO, "Model file empty");
|
||||
QFile modelFile(modelFileName);
|
||||
Q_ASSERT_X(modelFile.exists(), Q_FUNC_INFO, "Model file does not exist");
|
||||
QFile liveryFile(liveriesFileName);
|
||||
Q_ASSERT_X(liveryFile.exists(), Q_FUNC_INFO, "Liveries file does not exist");
|
||||
|
||||
out << "Loaded DB JSON model file " << modelFile.fileName() << endl;
|
||||
const QString modelData = CFileUtils::readFileToString(modelFile.fileName());
|
||||
Q_ASSERT_X(!modelData.isEmpty(), Q_FUNC_INFO, "Model file empty");
|
||||
|
||||
out << "Loaded DB JSON livery file " << liveryFile.fileName() << endl;
|
||||
const QString liveryData = CFileUtils::readFileToString(liveryFile.fileName());
|
||||
Q_ASSERT_X(!liveryData.isEmpty(), Q_FUNC_INFO, "Livery file empty");
|
||||
|
||||
// DB format, all models denormalized in DB JSON format
|
||||
CDatabaseReader::JsonDatastoreResponse response;
|
||||
CDatabaseReader::stringToDatastoreResponse(data, response);
|
||||
QTime timer;
|
||||
|
||||
CDatabaseReader::stringToDatastoreResponse(liveryData, response);
|
||||
timer.start();
|
||||
const CLiveryList dbLiveries = CLiveryList::fromDatabaseJson(response);
|
||||
int ms = timer.elapsed();
|
||||
out << "Read via DB JSON format: " << dbLiveries.size() << " liveries in " << ms << "ms" << endl;
|
||||
|
||||
// does not result in better performance, liveries/airlines have almost a 1:1 ratio
|
||||
// unlike models' fromDatabaseJsonCaching not many airlines will be recycled
|
||||
timer.start();
|
||||
const CLiveryList dbLiveries2 = CLiveryList::fromDatabaseJsonCaching(response);
|
||||
ms = timer.elapsed();
|
||||
out << "Read via DB JSON format (new): " << dbLiveries2.size() << " liveries in " << ms << "ms" << endl;
|
||||
|
||||
const CAirlineIcaoCodeList liveryAirlines = dbLiveries2.getAirlines();
|
||||
timer.start();
|
||||
const CLiveryList dbLiveries3 = CLiveryList::fromDatabaseJsonCaching(response, liveryAirlines);
|
||||
ms = timer.elapsed();
|
||||
out << "Read via DB JSON format (new, passing airlines): " << dbLiveries3.size() << " liveries in " << ms << "ms" << endl;
|
||||
|
||||
CDatabaseReader::stringToDatastoreResponse(modelData, response);
|
||||
timer.start();
|
||||
const CAircraftModelList dbModels = CAircraftModelList::fromDatabaseJson(response);
|
||||
int ms = timer.elapsed();
|
||||
ms = timer.elapsed();
|
||||
out << "Read via DB JSON format: " << dbModels.size() << " models in " << ms << "ms" << endl;
|
||||
|
||||
timer.start();
|
||||
const CAircraftModelList dbModels2 = CAircraftModelList::fromDatabaseJsonCaching(response);
|
||||
ms = timer.elapsed();
|
||||
out << "Read via DB JSON format (new): " << dbModels2.size() << " models in " << ms << "ms" << endl;
|
||||
|
||||
// swift JSON format
|
||||
const QJsonObject swiftJsonObject = dbModels.toJson();
|
||||
out << "Converted to swift JSON" << endl;
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace BlackSample
|
||||
static int samplesJson(QTextStream &out);
|
||||
|
||||
//! JSON loading (database vs. own format
|
||||
static int samplesJsonModel(QTextStream &out);
|
||||
static int samplesJsonModelAndLivery(QTextStream &out);
|
||||
|
||||
//! String manipulation (inserter)
|
||||
static int samplesStringUtilsVsRegEx(QTextStream &out);
|
||||
|
||||
@@ -387,7 +387,7 @@ namespace BlackCore
|
||||
if (res.isRestricted())
|
||||
{
|
||||
// create full list if it was just incremental
|
||||
const CAircraftModelList incrementalModels(CAircraftModelList::fromDatabaseJson(res));
|
||||
const CAircraftModelList incrementalModels(CAircraftModelList::fromDatabaseJsonCaching(res));
|
||||
if (incrementalModels.isEmpty()) { return; } // currently ignored
|
||||
models = this->getModels();
|
||||
models.replaceOrAddObjectsByKey(incrementalModels);
|
||||
@@ -396,7 +396,7 @@ namespace BlackCore
|
||||
{
|
||||
QTime time;
|
||||
time.start();
|
||||
models = CAircraftModelList::fromDatabaseJson(res);
|
||||
models = CAircraftModelList::fromDatabaseJsonCaching(res);
|
||||
this->logParseMessage("models", models.size(), time.elapsed(), res);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user