refs #322, performance samples

* menu for samples, no need to comment things out
This commit is contained in:
Klaus Basan
2014-09-04 01:27:58 +02:00
parent 00f3a78a66
commit 87e87013f9
6 changed files with 202 additions and 16 deletions

View File

@@ -32,6 +32,7 @@ namespace BlackMisc
template <class LATorLON> LATorLON CEarthAngle<LATorLON>::fromWgs84(const QString &wgsCoordinate)
{
// http://www.regular-expressions.info/floatingpoint.html
const QString wgs = wgsCoordinate.simplified().trimmed();
QRegExp rx("([-+]?[0-9]*\\.?[0-9]+)");
qint32 deg = 0;
qint32 min = 0;
@@ -40,7 +41,7 @@ namespace BlackMisc
int fragmentLength = 0;
int c = 0;
int pos = 0;
while ((pos = rx.indexIn(wgsCoordinate, pos)) != -1)
while ((pos = rx.indexIn(wgs, pos)) != -1)
{
QString cap = rx.cap(1);
pos += rx.matchedLength();
@@ -65,12 +66,12 @@ namespace BlackMisc
}
if (fragmentLength > 0)
{
// we do have given ms
// we do have given ms in string
sec += secFragment / qPow(10, fragmentLength);
}
if (wgsCoordinate.contains('S', Qt::CaseInsensitive) ||
wgsCoordinate.contains('W', Qt::CaseInsensitive)) deg *= -1;
if (wgs.contains('S', Qt::CaseInsensitive) ||
wgs.contains('W', Qt::CaseInsensitive)) deg *= -1;
CAngle a(deg, min, sec);
return LATorLON(a);

View File

@@ -31,7 +31,10 @@ namespace BlackMisc
CAtcStation CTesting::createStation(int index, bool byPropertyIndex)
{
// ATC station
// from WGS is slow, so static const (only 1 time init)
// https://dev.vatsim-germany.org/issues/322#note-2
static const CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21 13″ N", "11° 47 09″ E", CLength(index, CLengthUnit::ft()));
QString cs = QString("%1_TWR").arg(index);
QString usr = QString("Joe %1").arg(index);
QString id = QString("00000%1").arg(index).right(6);
@@ -39,11 +42,9 @@ namespace BlackMisc
QDateTime dtFrom = QDateTime::currentDateTimeUtc();
QDateTime dtUntil = dtFrom.addSecs(60 * 60.0); // 1 hour
CCoordinateGeodetic geoPos = CCoordinateGeodetic::fromWgs84("48° 21 13″ N", "11° 47 09″ E", CLength(index, CLengthUnit::ft()));
if (byPropertyIndex)
{
CAtcStation station;
station.setPropertyByIndex(CCallsign(cs).toQVariant(), CAtcStation::IndexCallsign);
station.setPropertyByIndex(CUser(id, usr).toQVariant(), CAtcStation::IndexController);
@@ -125,15 +126,34 @@ namespace BlackMisc
void CTesting::copy10kStations(int times)
{
int s = 0;
CAtcStationList stations;
for (int i = 0; i < times; i++)
{
stations = stations10k();
s += stations.size(); // make sure stations is used
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 CLength h(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), h);
}
Q_ASSERT(s == times * 10000);
Q_UNUSED(s);
}
} // namespace

View File

@@ -51,6 +51,8 @@ namespace BlackMisc
return s;
}
//! parse coordinates from WGS
static void parseWgs(int times);
};
} // Aviation