From 20921b79b8435211dc86d37573f2d10ff0b50234 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Sat, 11 Feb 2017 17:16:26 +0100 Subject: [PATCH] refs #875, refs #879, move functions only needed in performance samples to CSamplesPerformance Also made some sample functions private --- samples/blackmisc/samplesperformance.cpp | 115 +++++++++++++++++++++-- samples/blackmisc/samplesperformance.h | 21 ++++- src/blackmisc/test/testing.cpp | 93 ------------------ src/blackmisc/test/testing.h | 18 ---- src/blackmisc/test/testservice.cpp | 2 +- 5 files changed, 125 insertions(+), 124 deletions(-) diff --git a/samples/blackmisc/samplesperformance.cpp b/samples/blackmisc/samplesperformance.cpp index 83e71174e..dbfedecef 100644 --- a/samples/blackmisc/samplesperformance.cpp +++ b/samples/blackmisc/samplesperformance.cpp @@ -47,6 +47,7 @@ using namespace BlackMisc; using namespace BlackMisc::Aviation; using namespace BlackMisc::Geo; +using namespace BlackMisc::Network; using namespace BlackMisc::PhysicalQuantities; using namespace BlackMisc::Simulation; using namespace BlackMisc::Test; @@ -59,7 +60,7 @@ namespace BlackSample { QTime timer; int ms, number; - CTesting::copy10kStations(1); // init + CSamplesPerformance::copy10kStations(1); // init // ATC stations, tradionally created timer.start(); @@ -96,55 +97,55 @@ namespace BlackSample // Read data, this is what all our models do when displaying in a table view timer.start(); - CTesting::readStations(atcs1, false); + CSamplesPerformance::accessStationsData(atcs1, false); ms = timer.elapsed(); out << "Read (getters) " << atcs1.size() << " ATC stations in " << ms << "ms" << endl; timer.start(); - CTesting::readStations(atcs2, false); + CSamplesPerformance::accessStationsData(atcs2, false); ms = timer.elapsed(); out << "Read (getters) " << atcs2.size() << " ATC stations in " << ms << "ms" << endl; timer.start(); - CTesting::readStations(atcs1, true); + CSamplesPerformance::accessStationsData(atcs1, true); ms = timer.elapsed(); out << "Read (propertyIndex) " << atcs1.size() << " ATC stations in " << ms << "ms" << endl; timer.start(); - CTesting::readStations(atcs2, true); + CSamplesPerformance::accessStationsData(atcs2, true); ms = timer.elapsed(); out << "Read (propertyIndex) " << atcs2.size() << " ATC stations in " << ms << "ms" << endl; // calculate number = 10000; timer.start(); - CTesting::calculateDistance(number); + CSamplesPerformance::calculateDistance(number); ms = timer.elapsed(); out << "Calculated distances " << number << " in " << ms << "ms" << endl; number = 100000; timer.start(); - CTesting::calculateDistance(number); + CSamplesPerformance::calculateDistance(number); ms = timer.elapsed(); out << "Calculated distances " << number << "in " << ms << "ms" << endl; // parse number = 100000; timer.start(); - CTesting::parseWgs(number); + CSamplesPerformance::parseWgs(number); ms = timer.elapsed(); out << "Parse WGS coordinates " << number << " in " << ms << "ms" << endl; // copy timer.start(); number = 20; - CTesting::copy10kStations(number); + CSamplesPerformance::copy10kStations(number); ms = timer.elapsed(); out << "Copied 10k stations " << number << " times in " << ms << "ms" << endl; timer.start(); number = 100; - CTesting::copy10kStations(number); + CSamplesPerformance::copy10kStations(number); ms = timer.elapsed(); out << "Copied 10k stations " << number << " times in " << ms << "ms" << endl; @@ -608,4 +609,98 @@ namespace BlackSample } return models; } + + void CSamplesPerformance::calculateDistance(int n) + { + if (n < 1) return; + CAtcStation atc = CTesting::createStation(1); + QList 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 diff --git a/samples/blackmisc/samplesperformance.h b/samples/blackmisc/samplesperformance.h index f36dfc48e..e1e91623b 100644 --- a/samples/blackmisc/samplesperformance.h +++ b/samples/blackmisc/samplesperformance.h @@ -47,15 +47,32 @@ namespace BlackSample //! String manipulation (concatenation) static int samplesStringConcat(QTextStream &out); + private: + static const qint64 DeltaTime = 10; + //! Situation values for testing static BlackMisc::Aviation::CAircraftSituationList createSituations(qint64 baseTimeEpoch, int numberOfCallsigns, int numberOfTimes); //! Model values for testing static BlackMisc::Simulation::CAircraftModelList createModels(int numberOfModels, int numberOfMemoParts); - private: - static const qint64 DeltaTime = 10; + //! 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(); + + //! 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 diff --git a/src/blackmisc/test/testing.cpp b/src/blackmisc/test/testing.cpp index c865bb6c0..7d94124cb 100644 --- a/src/blackmisc/test/testing.cpp +++ b/src/blackmisc/test/testing.cpp @@ -86,99 +86,6 @@ namespace BlackMisc 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 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 list; diff --git a/src/blackmisc/test/testing.h b/src/blackmisc/test/testing.h index 626b1ddef..685d099a7 100644 --- a/src/blackmisc/test/testing.h +++ b/src/blackmisc/test/testing.h @@ -34,12 +34,6 @@ namespace BlackMisc //! Single station, annotated by index 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 static BlackMisc::Simulation::FsCommon::CAircraftCfgEntriesList getAircraftCfgEntries(int number); @@ -48,18 +42,6 @@ namespace BlackMisc //! Get clients 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 diff --git a/src/blackmisc/test/testservice.cpp b/src/blackmisc/test/testservice.cpp index ac453e992..1135b41e3 100644 --- a/src/blackmisc/test/testservice.cpp +++ b/src/blackmisc/test/testservice.cpp @@ -8,8 +8,8 @@ */ #include "testservice.h" -#include "testutils.h" #include "testing.h" +#include "blackmisc/dbusutils.h" #include "blackmisc/aviation/callsign.h" #include "blackmisc/aviation/comsystem.h" #include "blackmisc/aviation/track.h"