refs #875, refs #879, move functions only needed in performance samples to CSamplesPerformance

Also made some sample functions private
This commit is contained in:
Klaus Basan
2017-02-11 17:16:26 +01:00
committed by Mathew Sutcliffe
parent dc1d5d8586
commit 20921b79b8
5 changed files with 125 additions and 124 deletions

View File

@@ -47,6 +47,7 @@
using namespace BlackMisc; using namespace BlackMisc;
using namespace BlackMisc::Aviation; using namespace BlackMisc::Aviation;
using namespace BlackMisc::Geo; using namespace BlackMisc::Geo;
using namespace BlackMisc::Network;
using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::PhysicalQuantities;
using namespace BlackMisc::Simulation; using namespace BlackMisc::Simulation;
using namespace BlackMisc::Test; using namespace BlackMisc::Test;
@@ -59,7 +60,7 @@ namespace BlackSample
{ {
QTime timer; QTime timer;
int ms, number; int ms, number;
CTesting::copy10kStations(1); // init CSamplesPerformance::copy10kStations(1); // init
// ATC stations, tradionally created // ATC stations, tradionally created
timer.start(); timer.start();
@@ -96,55 +97,55 @@ namespace BlackSample
// Read data, this is what all our models do when displaying in a table view // Read data, this is what all our models do when displaying in a table view
timer.start(); timer.start();
CTesting::readStations(atcs1, false); CSamplesPerformance::accessStationsData(atcs1, false);
ms = timer.elapsed(); ms = timer.elapsed();
out << "Read (getters) " << atcs1.size() << " ATC stations in " << ms << "ms" << endl; out << "Read (getters) " << atcs1.size() << " ATC stations in " << ms << "ms" << endl;
timer.start(); timer.start();
CTesting::readStations(atcs2, false); CSamplesPerformance::accessStationsData(atcs2, false);
ms = timer.elapsed(); ms = timer.elapsed();
out << "Read (getters) " << atcs2.size() << " ATC stations in " << ms << "ms" << endl; out << "Read (getters) " << atcs2.size() << " ATC stations in " << ms << "ms" << endl;
timer.start(); timer.start();
CTesting::readStations(atcs1, true); CSamplesPerformance::accessStationsData(atcs1, true);
ms = timer.elapsed(); ms = timer.elapsed();
out << "Read (propertyIndex) " << atcs1.size() << " ATC stations in " << ms << "ms" << endl; out << "Read (propertyIndex) " << atcs1.size() << " ATC stations in " << ms << "ms" << endl;
timer.start(); timer.start();
CTesting::readStations(atcs2, true); CSamplesPerformance::accessStationsData(atcs2, true);
ms = timer.elapsed(); ms = timer.elapsed();
out << "Read (propertyIndex) " << atcs2.size() << " ATC stations in " << ms << "ms" << endl; out << "Read (propertyIndex) " << atcs2.size() << " ATC stations in " << ms << "ms" << endl;
// calculate // calculate
number = 10000; number = 10000;
timer.start(); timer.start();
CTesting::calculateDistance(number); CSamplesPerformance::calculateDistance(number);
ms = timer.elapsed(); ms = timer.elapsed();
out << "Calculated distances " << number << " in " << ms << "ms" << endl; out << "Calculated distances " << number << " in " << ms << "ms" << endl;
number = 100000; number = 100000;
timer.start(); timer.start();
CTesting::calculateDistance(number); CSamplesPerformance::calculateDistance(number);
ms = timer.elapsed(); ms = timer.elapsed();
out << "Calculated distances " << number << "in " << ms << "ms" << endl; out << "Calculated distances " << number << "in " << ms << "ms" << endl;
// parse // parse
number = 100000; number = 100000;
timer.start(); timer.start();
CTesting::parseWgs(number); CSamplesPerformance::parseWgs(number);
ms = timer.elapsed(); ms = timer.elapsed();
out << "Parse WGS coordinates " << number << " in " << ms << "ms" << endl; out << "Parse WGS coordinates " << number << " in " << ms << "ms" << endl;
// copy // copy
timer.start(); timer.start();
number = 20; number = 20;
CTesting::copy10kStations(number); CSamplesPerformance::copy10kStations(number);
ms = timer.elapsed(); ms = timer.elapsed();
out << "Copied 10k stations " << number << " times in " << ms << "ms" << endl; out << "Copied 10k stations " << number << " times in " << ms << "ms" << endl;
timer.start(); timer.start();
number = 100; number = 100;
CTesting::copy10kStations(number); CSamplesPerformance::copy10kStations(number);
ms = timer.elapsed(); ms = timer.elapsed();
out << "Copied 10k stations " << number << " times in " << ms << "ms" << endl; out << "Copied 10k stations " << number << " times in " << ms << "ms" << endl;
@@ -608,4 +609,98 @@ namespace BlackSample
} }
return models; return models;
} }
void CSamplesPerformance::calculateDistance(int n)
{
if (n < 1) return;
CAtcStation atc = CTesting::createStation(1);
QList<CCoordinateGeodetic> pos(
{
CCoordinateGeodetic(10.0, 10.0, 10.0),
CCoordinateGeodetic(20.0, 20.0, 20.0),
CCoordinateGeodetic(30.0, 30.0, 30.0),
CCoordinateGeodetic(40.0, 40.0, 40.0),
CCoordinateGeodetic(50.0, 50.0, 50.0),
CCoordinateGeodetic(60.0, 60.0, 60.0),
CCoordinateGeodetic(70.0, 70.0, 70.0)
}
);
const int s = pos.size();
for (int i = 0; i < n; i++)
{
int p = i % s;
atc.calculcateAndUpdateRelativeDistance(pos.at(p));
}
}
void CSamplesPerformance::copy10kStations(int times)
{
CAtcStationList stations;
for (int i = 0; i < times; i++)
{
stations = stations10k();
stations.pop_back(); // make sure stations are really copied (copy-on-write)
}
}
void CSamplesPerformance::parseWgs(int times)
{
static QStringList wgsLatLng(
{
"12° 11 10″ N", "11° 22 33″ W",
"48° 21 13″ N", "11° 47 09″ E",
" 8° 21 13″ N", "11° 47 09″ W",
"18° 21 13″ S", "11° 47 09″ E",
"09° 12 13″ S", "11° 47 09″ W"
});
CCoordinateGeodetic c;
const CAltitude a(333, CLengthUnit::m());
for (int i = 0; i < times; i++)
{
int idx = (i % 5) * 2;
c = CCoordinateGeodetic::fromWgs84(wgsLatLng.at(idx), wgsLatLng.at(idx + 1), a);
}
}
const CAtcStationList &CSamplesPerformance::stations10k()
{
static const CAtcStationList s = CTesting::createAtcStations(10000, false);
return s;
}
void CSamplesPerformance::accessStationsData(const CAtcStationList &stations, bool byPropertyIndex)
{
for (const CAtcStation &station : stations)
{
const QString s = CSamplesPerformance::accessStationData(station, byPropertyIndex);
Q_UNUSED(s);
}
}
QString CSamplesPerformance::accessStationData(const CAtcStation &station, bool byPropertyIndex)
{
QString r;
if (byPropertyIndex)
{
r.append(station.propertyByIndex({ CAtcStation::IndexCallsign, CCallsign::IndexString}).toQString());
r.append(station.propertyByIndex({ CAtcStation::IndexController, CUser::IndexRealName}).toQString());
r.append(station.propertyByIndex({ CAtcStation::IndexPosition, CCoordinateGeodetic::IndexLatitudeAsString}).toQString());
r.append(station.propertyByIndex({ CAtcStation::IndexPosition, CCoordinateGeodetic::IndexLongitudeAsString}).toQString());
r.append(station.propertyByIndex({ CAtcStation::IndexRelativeDistance, CLength::IndexValueRounded2DigitsWithUnit}).toQString());
r.append(station.propertyByIndex({ CAtcStation::IndexBookedFrom}).toDateTime().toString("yyyy-MM-dd hh:mm"));
r.append(station.propertyByIndex({ CAtcStation::IndexBookedUntil}).toDateTime().toString("yyyy-MM-dd hh:mm"));
}
else
{
r.append(station.getCallsignAsString());
r.append(station.getController().getRealName());
r.append(station.getPosition().latitudeAsString());
r.append(station.getPosition().longitudeAsString());
r.append(station.getRelativeDistance().toQString(true));
r.append(station.getBookedFromUtc().toString("yyyy-MM-dd hh:mm"));
r.append(station.getBookedUntilUtc().toString("yyyy-MM-dd hh:mm"));
}
return r;
}
} // namespace } // namespace

View File

@@ -47,15 +47,32 @@ namespace BlackSample
//! String manipulation (concatenation) //! String manipulation (concatenation)
static int samplesStringConcat(QTextStream &out); static int samplesStringConcat(QTextStream &out);
private:
static const qint64 DeltaTime = 10;
//! 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);
//! Model values for testing //! Model values for testing
static BlackMisc::Simulation::CAircraftModelList createModels(int numberOfModels, int numberOfMemoParts); static BlackMisc::Simulation::CAircraftModelList createModels(int numberOfModels, int numberOfMemoParts);
private: //! Calculate n times distance (greater circle distance)
static const qint64 DeltaTime = 10; static void calculateDistance(int n);
//! Copy 10k stations n times
static void copy10kStations(int times);
//! Const 10000 stations
static const BlackMisc::Aviation::CAtcStationList &stations10k();
//! Access properties of given stations
static void accessStationsData(const BlackMisc::Aviation::CAtcStationList &stations, bool byPropertyIndex = false);
//! Read properties of a station and concatenate them
static QString accessStationData(const BlackMisc::Aviation::CAtcStation &station, bool byPropertyIndex = false);
//! parse coordinates from WGS
static void parseWgs(int times);
}; };
} // namespace } // namespace

View File

@@ -86,99 +86,6 @@ namespace BlackMisc
return station; return station;
} }
void CTesting::readStations(const CAtcStationList &stations, bool byPropertyIndex)
{
foreach (const CAtcStation station, stations)
{
accessStationData(station, byPropertyIndex);
}
}
QString CTesting::accessStationData(const CAtcStation &station, bool byPropertyIndex)
{
QString r;
if (byPropertyIndex)
{
r.append(station.propertyByIndex({ CAtcStation::IndexCallsign, CCallsign::IndexString}).toQString());
r.append(station.propertyByIndex({ CAtcStation::IndexController, CUser::IndexRealName}).toQString());
r.append(station.propertyByIndex({ CAtcStation::IndexPosition, CCoordinateGeodetic::IndexLatitudeAsString}).toQString());
r.append(station.propertyByIndex({ CAtcStation::IndexPosition, CCoordinateGeodetic::IndexLongitudeAsString}).toQString());
r.append(station.propertyByIndex({ CAtcStation::IndexRelativeDistance, CLength::IndexValueRounded2DigitsWithUnit}).toQString());
r.append(station.propertyByIndex({ CAtcStation::IndexBookedFrom}).toDateTime().toString("yyyy-MM-dd hh:mm"));
r.append(station.propertyByIndex({ CAtcStation::IndexBookedUntil}).toDateTime().toString("yyyy-MM-dd hh:mm"));
}
else
{
r.append(station.getCallsignAsString());
r.append(station.getController().getRealName());
r.append(station.getPosition().latitudeAsString());
r.append(station.getPosition().longitudeAsString());
r.append(station.getRelativeDistance().toQString(true));
r.append(station.getBookedFromUtc().toString("yyyy-MM-dd hh:mm"));
r.append(station.getBookedUntilUtc().toString("yyyy-MM-dd hh:mm"));
}
return r;
}
void CTesting::calculateDistance(int n)
{
if (n < 1) return;
CAtcStation atc = createStation(1);
QList<CCoordinateGeodetic> pos(
{
CCoordinateGeodetic(10.0, 10.0, 10.0),
CCoordinateGeodetic(20.0, 20.0, 20.0),
CCoordinateGeodetic(30.0, 30.0, 30.0),
CCoordinateGeodetic(40.0, 40.0, 40.0),
CCoordinateGeodetic(50.0, 50.0, 50.0),
CCoordinateGeodetic(60.0, 60.0, 60.0),
CCoordinateGeodetic(70.0, 70.0, 70.0)
}
);
const int s = pos.size();
for (int i = 0; i < n; i++)
{
int p = i % s;
atc.calculcateAndUpdateRelativeDistance(pos.at(p));
}
}
void CTesting::copy10kStations(int times)
{
CAtcStationList stations;
for (int i = 0; i < times; i++)
{
stations = stations10k();
stations.pop_back(); // make sure stations are really copied (copy-on-write)
}
}
void CTesting::parseWgs(int times)
{
static QStringList wgsLatLng(
{
"12° 11 10″ N", "11° 22 33″ W",
"48° 21 13″ N", "11° 47 09″ E",
" 8° 21 13″ N", "11° 47 09″ W",
"18° 21 13″ S", "11° 47 09″ E",
"09° 12 13″ S", "11° 47 09″ W"
});
CCoordinateGeodetic c;
const CAltitude a(333, CLengthUnit::m());
for (int i = 0; i < times; i++)
{
int idx = (i % 5) * 2;
c = CCoordinateGeodetic::fromWgs84(wgsLatLng.at(idx), wgsLatLng.at(idx + 1), a);
}
}
const CAtcStationList &CTesting::stations10k()
{
static const CAtcStationList s = createAtcStations(10000, false);
return s;
}
CAircraftCfgEntriesList CTesting::getAircraftCfgEntries(int number) CAircraftCfgEntriesList CTesting::getAircraftCfgEntries(int number)
{ {
CAircraftCfgEntriesList list; CAircraftCfgEntriesList list;

View File

@@ -34,12 +34,6 @@ namespace BlackMisc
//! Single station, annotated by index //! Single station, annotated by index
static BlackMisc::Aviation::CAtcStation createStation(int index, bool byPropertyIndex = false); static BlackMisc::Aviation::CAtcStation createStation(int index, bool byPropertyIndex = false);
//! Generate number of ATC stations
static void readStations(const BlackMisc::Aviation::CAtcStationList &stations, bool byPropertyIndex = false);
//! Read properties of a station and concatenate them
static QString accessStationData(const BlackMisc::Aviation::CAtcStation &station, bool byPropertyIndex = false);
//! Get aircraft cfg entries //! Get aircraft cfg entries
static BlackMisc::Simulation::FsCommon::CAircraftCfgEntriesList getAircraftCfgEntries(int number); static BlackMisc::Simulation::FsCommon::CAircraftCfgEntriesList getAircraftCfgEntries(int number);
@@ -48,18 +42,6 @@ namespace BlackMisc
//! Get clients //! Get clients
static BlackMisc::Network::CClientList getClients(int number); static BlackMisc::Network::CClientList getClients(int number);
//! Calculate n times distance (greater circle distance)
static void calculateDistance(int n);
//! Copy 10k stations n times
static void copy10kStations(int times);
//! Const 10000 stations
static const BlackMisc::Aviation::CAtcStationList &stations10k();
//! parse coordinates from WGS
static void parseWgs(int times);
}; };
} // ns } // ns
} // ns } // ns

View File

@@ -8,8 +8,8 @@
*/ */
#include "testservice.h" #include "testservice.h"
#include "testutils.h"
#include "testing.h" #include "testing.h"
#include "blackmisc/dbusutils.h"
#include "blackmisc/aviation/callsign.h" #include "blackmisc/aviation/callsign.h"
#include "blackmisc/aviation/comsystem.h" #include "blackmisc/aviation/comsystem.h"
#include "blackmisc/aviation/track.h" #include "blackmisc/aviation/track.h"