|
View:
New views
3 Messages
—
Rating Filter:
Alert me
|
|
|
KDE/kdeedu/kstars/kstarsSVN commit 1045844 by khudyakov:
Remove radian caching from dms. It's not really sensible to cache results of multiplication. It's better to save some space CCMAIL: kstars-devel@... M +0 -14 dms.cpp M +7 -11 dms.h --- trunk/KDE/kdeedu/kstars/kstars/dms.cpp #1045843:1045844 @@ -27,14 +27,12 @@ void dms::setD( const double &x ) { D = x; scDirty = true; - rDirty = true; } void dms::setD(const int &d, const int &m, const int &s, const int &ms) { D = (double)abs(d) + ((double)m + ((double)s + (double)ms/1000.)/60.)/60.; if (d<0) {D = -1.0*D;} scDirty = true; - rDirty = true; } void dms::setH( const double &x ) { @@ -45,14 +43,11 @@ D = 15.0*((double)abs(h) + ((double)m + ((double)s + (double)ms/1000.)/60.)/60.); if (h<0) {D = -1.0*D;} scDirty = true; - rDirty = true; } void dms::setRadians( const double &Rad ) { setD( Rad/DegToRad ); - Radians = Rad; scDirty = true; - rDirty = true; } bool dms::setFromString( const QString &str, bool isDeg ) { @@ -254,15 +249,6 @@ cosa = Cos; } -const double& dms::radians( void ) const { - if ( rDirty ) { - Radians = D*DegToRad; - rDirty = false; - } - - return Radians; -} - const dms dms::reduce( void ) const { double a = D; while (a<0.0) {a += 360.0;} --- trunk/KDE/kdeedu/kstars/kstars/dms.h #1045843:1045844 @@ -279,7 +279,7 @@ *@return the Sine of the angle. *@sa cos() */ - const double& sin( void ) const; + const double& sin() const; /**@short Compute the Angle's Cosine. * @@ -289,15 +289,12 @@ *@return the Cosine of the angle. *@sa sin() */ - const double& cos( void ) const; + const double& cos() const; /**@short Express the angle in radians. - *The computed Radians value is stored internally. On subsequent calls, - *the stored value is returned directly (unless the angle's value has - *changed). - *@return the angle in radians (double) - */ - const double& radians( void ) const; + * @return the angle in radians (double) + */ + double radians() const { return D*DegToRad; } /**@short Set angle according to the argument, in radians. * @@ -310,7 +307,7 @@ /**return the equivalent angle between 0 and 360 degrees. *@warning does not change the value of the parent angle itself. */ - const dms reduce( void ) const; + const dms reduce() const; /**@return a nicely-formatted string representation of the angle *in degrees, arcminutes, and arcseconds. @@ -351,9 +348,8 @@ private: double D; - mutable double Radians; mutable double Sin, Cos; - mutable bool scDirty, rDirty; + mutable bool scDirty; }; #endif _______________________________________________ Kstars-devel mailing list Kstars-devel@... https://mail.kde.org/mailman/listinfo/kstars-devel |
|
|
Re: KDE/kdeedu/kstars/kstarsВ сообщении от 07 ноября 2009 00:13:21 Alexey Khudyakov написал:
> SVN commit 1045844 by khudyakov: > > Remove radian caching from dms. It's not really sensible to > cache results of multiplication. It's better to save some space > Follow up on DMS caching Here nice plot showing caching efficiency as function of time. Efficiency is defined as ratio of all cache hits to all cache misses so far. I made two measurements. In 'idle' I simply left KStars running for few minutes. In 'active' I dragged sky around, zoomed in/out. Ratio is quite low, it's in 0.5-0.6 range. Or in other words only about 1 call in 3 is cached. This leads me to question efficiency of sin/cos caching. In attachment plot and patch used for measurements [cache_efficiency.patch] diff --git a/kstars/kstars/dms.cpp b/kstars/kstars/dms.cpp index 875a46b..66b4d21 100644 --- a/kstars/kstars/dms.cpp +++ b/kstars/kstars/dms.cpp @@ -24,6 +24,15 @@ #include <kglobal.h> #include <klocale.h> +#include <QTime> +namespace { + int cacheHit = 0; + int cacheMiss = 0; + int cnt = 0; + + QTime t0; +} + void dms::setD( const double &x ) { D = x; scDirty = true; @@ -212,8 +221,9 @@ const double& dms::sin( void ) const { if ( scDirty ) { double s,c; SinCos( s, c ); + } else { + cacheHit++; } - return Sin; } @@ -221,8 +231,9 @@ const double& dms::cos( void ) const { if ( scDirty ) { double s,c; SinCos( s, c ); + } else { + cacheHit++; } - return Cos; } @@ -233,6 +244,8 @@ void dms::SinCos( double &sina, double &cosa ) const { * GNU extension sincos() is defined. */ + if( !t0.isValid() ) + t0 = QTime::currentTime(); if ( scDirty ) { #ifdef __GLIBC__ #if ( __GLIBC__ >= 2 && __GLIBC_MINOR__ >=1 && !defined(__UCLIBC__)) @@ -249,6 +262,15 @@ void dms::SinCos( double &sina, double &cosa ) const { Cos = ::cos( radians() ); #endif scDirty = false; + cacheMiss++; + } else { + cacheHit++; + } + if( cnt++ == 5000 ) { + cnt = 0; + kDebug() << QString("t=%1, hit=%2, miss=%3, ratio=%4"). + arg( t0.msecsTo( QTime::currentTime() ) ). + arg(cacheHit).arg(cacheMiss).arg(((double)cacheHit)/cacheMiss); } sina = Sin; cosa = Cos; _______________________________________________ Kstars-devel mailing list Kstars-devel@... https://mail.kde.org/mailman/listinfo/kstars-devel |
|
|
Remove caching from dms (was: KDE/kdeedu/kstars/kstars)В сообщении от 07 ноября 2009 16:31:35 Khudyakov Alexey написал:
> В сообщении от 07 ноября 2009 00:13:21 Alexey Khudyakov написал: > > SVN commit 1045844 by khudyakov: > > > > Remove radian caching from dms. It's not really sensible to > > cache results of multiplication. It's better to save some space > > Follow up on DMS caching > > Here nice plot showing caching efficiency as function of time. Efficiency > is defined as ratio of all cache hits to all cache misses so far. I made > two measurements. In 'idle' I simply left KStars running for few minutes. > In 'active' I dragged sky around, zoomed in/out. > > Ratio is quite low, it's in 0.5-0.6 range. Or in other words only about 1 > call in 3 is cached. This leads me to question efficiency of sin/cos > caching. > replaced current caching version of sincos with inlined call to sincos it become about 1.5 times faster. So I propose to remove caching. Also it decrease size of dms to size of double and make it cheap to pass/return it by value. _______________________________________________ Kstars-devel mailing list Kstars-devel@... https://mail.kde.org/mailman/listinfo/kstars-devel |
| Free embeddable forum powered by Nabble | Forum Help |