summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAkarsh Simha <akarsh@kde.org>2016-09-24 22:18:42 (GMT)
committerAkarsh Simha <akarsh@kde.org>2016-09-28 22:16:20 (GMT)
commitb91a0c3768d58c3c6b62fc0b3c8d50043d180add (patch)
treea2c7ed0f6a19915ff813f88a48d332bba8f4c46a
parent0860ef61054d5ceee931aa90806e16d99ad12b9a (diff)
Profile trigonometric function calls to dms objects
-rw-r--r--kstars/auxiliary/dms.cpp1
-rw-r--r--kstars/auxiliary/dms.h43
-rw-r--r--kstars/skycomponents/deepstarcomponent.cpp8
3 files changed, 50 insertions, 2 deletions
diff --git a/kstars/auxiliary/dms.cpp b/kstars/auxiliary/dms.cpp
index be1de35..b457be1 100644
--- a/kstars/auxiliary/dms.cpp
+++ b/kstars/auxiliary/dms.cpp
@@ -28,6 +28,7 @@ long unsigned dms::dms_constructor_calls = 0;
long unsigned dms::dms_with_sincos_called = 0;
long unsigned dms::trig_function_calls = 0;
long unsigned dms::redundant_trig_function_calls = 0;
+double dms::seconds_in_trig = 0;
#endif
void dms::setD(const int &d, const int &m, const int &s, const int &ms) {
diff --git a/kstars/auxiliary/dms.h b/kstars/auxiliary/dms.h
index 65c2517..b07fbab 100644
--- a/kstars/auxiliary/dms.h
+++ b/kstars/auxiliary/dms.h
@@ -26,6 +26,11 @@
#include <cmath>
#define COUNT_DMS_SINCOS_CALLS true
+#define PROFILE_SINCOS true
+
+#ifdef PROFILE_SINCOS
+#include <ctime>
+#endif
/** @class dms
* @short An angle, stored as degrees, but expressible in many ways.
@@ -241,7 +246,18 @@ public:
++redundant_trig_function_calls;
++trig_function_calls;
#endif
- return ::sin(D*DegToRad); }
+#ifdef PROFILE_SINCOS
+ std::clock_t start, stop;
+ double s;
+ start = std::clock();
+ s = ::sin(D*DegToRad);
+ stop = std::clock();
+ seconds_in_trig += double(stop - start)/double(CLOCKS_PER_SEC);
+ return s;
+#else
+ return ::sin(D*DegToRad);
+#endif
+ }
/** @short Compute the Angle's Cosine.
*
@@ -257,7 +273,18 @@ public:
++redundant_trig_function_calls;
++trig_function_calls;
#endif
- return ::cos(D*DegToRad); }
+#ifdef PROFILE_SINCOS
+ std::clock_t start, stop;
+ double c;
+ start = std::clock();
+ c = ::cos(D*DegToRad);
+ stop = std::clock();
+ seconds_in_trig += double(stop - start)/double(CLOCKS_PER_SEC);
+ return c;
+#else
+ return ::cos(D*DegToRad);
+#endif
+ }
/** @short Express the angle in radians.
* @return the angle in radians (double)
@@ -321,6 +348,7 @@ public:
static long unsigned dms_with_sincos_called;
static long unsigned trig_function_calls; // total number of trig function calls
static long unsigned redundant_trig_function_calls; // counts number of redundant trig function calls
+ static double seconds_in_trig; // accumulates number of seconds spent in trig function calls
#endif
private:
double D;
@@ -344,6 +372,11 @@ inline dms operator - (dms a, dms b) {
// Inline sincos
inline void dms::SinCos(double& s, double& c) const {
+#ifdef PROFILE_SINCOS
+ std::clock_t start, stop;
+ start = std::clock();
+#endif
+
#ifdef __GLIBC__
#if ( __GLIBC__ >= 2 && __GLIBC_MINOR__ >=1 && !defined(__UCLIBC__))
//GNU version
@@ -358,6 +391,12 @@ inline void dms::SinCos(double& s, double& c) const {
s = ::sin( radians() );
c = ::cos( radians() );
#endif
+
+#ifdef PROFILE_SINCOS
+ stop = std::clock();
+ seconds_in_trig += double(stop - start)/double(CLOCKS_PER_SEC);
+#endif
+
#ifdef COUNT_DMS_SINCOS_CALLS
if( !m_sinCosCalled ) { m_sinCosCalled = true; ++dms_with_sincos_called; }
if( m_sinDirty )
diff --git a/kstars/skycomponents/deepstarcomponent.cpp b/kstars/skycomponents/deepstarcomponent.cpp
index d1f432d..09c616e 100644
--- a/kstars/skycomponents/deepstarcomponent.cpp
+++ b/kstars/skycomponents/deepstarcomponent.cpp
@@ -185,6 +185,10 @@ void DeepStarComponent::draw( SkyPainter *skyp ) {
#ifndef KSTARS_LITE
if ( !fileOpened ) return;
+#ifdef PROFILE_SINCOS
+ long trig_calls_here = - dms::trig_function_calls;
+ dms::seconds_in_trig = 0.;
+#endif
SkyMap *map = SkyMap::Instance();
KStarsData* data = KStarsData::Instance();
UpdateID updateID = data->updateID();
@@ -313,6 +317,10 @@ void DeepStarComponent::draw( SkyPainter *skyp ) {
}
m_skyMesh->inDraw( false );
+#ifdef PROFILE_SINCOS
+ trig_calls_here += dms::trig_function_calls;
+ qDebug() << "Spent " << dms::seconds_in_trig << " seconds doing " << trig_calls_here << " trigonometric function calls amounting to an average of " << 1000.0 * dms::seconds_in_trig/double( trig_calls_here ) << " ms per call";
+#endif
#else
Q_UNUSED(skyp)
#endif