[Kst] extragear/graphics/kst/kst
George Staikos
staikos at kde.org
Wed Oct 26 21:19:13 CEST 2005
SVN commit 474575 by staikos:
add a cache for the more commonly called scalars to avoid dict lookups in the
update thread -> cpu load reduction during updates.
Also inlined accessors and de-virtualized length() since no-one was overriding
it. Make sure you make clean before rebuilding.
M +28 -75 kstvector.cpp
M +12 -10 kstvector.h
--- trunk/extragear/graphics/kst/kst/kstvector.cpp #474574:474575
@@ -170,6 +170,7 @@
void KstVector::CreateScalars() {
if (!_isScalarList) {
+ _min = _max = _mean = _minPos = 0.0;
_scalars.insert("max", new KstScalar(tagName() + "-Max"));
_scalars["max"]->_KShared_ref();
_scalars.insert("min", new KstScalar(tagName() + "-Min"));
@@ -213,14 +214,15 @@
_scalars["ns"]->setValue(_size);
if (_nsum >= 2) {
- _scalars["mean"]->setValue(_scalars["sum"]->value()/double(_nsum));
- _scalars["sigma"]->setValue( sqrt(
- (_scalars["sumsquared"]->value() - _scalars["sum"]->value()*_scalars["sum"]->value()/double(_nsum))/ double(_nsum-1) ) );
- _scalars["rms"]->setValue(sqrt(_scalars["sumsquared"]->value()/double(_nsum)));
+ double sum = _scalars["sum"]->value();
+ double sumsq;
+ _scalars["mean"]->setValue(_mean = sum/double(_nsum));
+ _scalars["sigma"]->setValue(sumsq = sqrt((_scalars["sumsquared"]->value() - sum * sum / double(_nsum)) / double(_nsum-1)));
+ _scalars["rms"]->setValue(sqrt(sumsq/double(_nsum)));
} else {
- _scalars["sigma"]->setValue(_scalars["max"]->value() - _scalars["min"]->value());
+ _scalars["sigma"]->setValue(_max - _min);
_scalars["rms"]->setValue(sqrt(_scalars["sumsquared"]->value()));
- _scalars["mean"]->setValue(0);
+ _scalars["mean"]->setValue(_mean = 0);
}
}
}
@@ -314,10 +316,10 @@
KstObject::UpdateType KstVector::internalUpdate(KstObject::UpdateType providerRC) {
int i, i0;
- double max, min, sum, sum2, minpos, last, v;
+ double sum, sum2, last, v;
double last_v;
double dv2 = 0.0, dv, no_spike_max_dv;
- max = min = sum = sum2 = minpos = last = 0.0;
+ _max = _min = sum = sum2 = _minPos = last = 0.0;
_nsum = 0;
if (_size > 0) {
_is_rising = true;
@@ -329,9 +331,9 @@
if (!_isScalarList) {
_scalars["sum"]->setValue(sum);
_scalars["sumsquared"]->setValue(sum2);
- _scalars["max"]->setValue(max);
- _scalars["min"]->setValue(min);
- _scalars["minpos"]->setValue(minpos);
+ _scalars["max"]->setValue(_max);
+ _scalars["min"]->setValue(_min);
+ _scalars["minpos"]->setValue(_minPos);
_scalars["last"]->setValue(last);
}
_ns_max = _ns_min = 0;
@@ -346,13 +348,13 @@
_is_rising = false;
}
- max = min = _v[i0];
+ _max = _min = _v[i0];
sum = sum2 = 0.0;
if (_v[i0] > 0) {
- minpos = _v[i0];
+ _minPos = _v[i0];
} else {
- minpos = 1.0E300;
+ _minPos = 1.0E300;
}
last_v = _v[i0];
@@ -375,13 +377,13 @@
sum += v;
sum2 += v*v;
- if (v > max) {
- max = v;
- } else if (v < min) {
- min = v;
+ if (v > _max) {
+ _max = v;
+ } else if (v < _min) {
+ _min = v;
}
- if (v < minpos && v > 0) {
- minpos = v;
+ if (v < _minPos && v > 0) {
+ _minPos = v;
}
} else {
_is_rising = false;
@@ -414,12 +416,14 @@
}
}
- if (!_isScalarList) {
+ if (_isScalarList) {
+ _max = _min = _minPos = 0.0;
+ } else {
_scalars["sum"]->setValue(sum);
_scalars["sumsquared"]->setValue(sum2);
- _scalars["max"]->setValue(max);
- _scalars["min"]->setValue(min);
- _scalars["minpos"]->setValue(minpos);
+ _scalars["max"]->setValue(_max);
+ _scalars["min"]->setValue(_min);
+ _scalars["minpos"]->setValue(_minPos);
_scalars["last"]->setValue(last);
}
@@ -466,62 +470,11 @@
}
-double KstVector::min() const {
- if (!_isScalarList) {
- return _scalars["min"]->value();
- } else {
- return 0.0;
- }
-}
-
-
-double KstVector::max() const {
- if (!_isScalarList) {
- return _scalars["max"]->value();
- } else {
- return 0.0;
- }
-}
-
-
-double KstVector::mean() const {
- if (!_isScalarList) {
- return _scalars["mean"]->value();
- } else {
- return 0.0;
- }
-}
-
-
-double KstVector::minPos() const {
- if (!_isScalarList) {
- return _scalars["minpos"]->value();
- } else {
- return 0.0;
- }
-}
-
-
-int KstVector::numNew() const {
- return NumNew;
-}
-
-
-int KstVector::numShift() const {
- return NumShifted;
-}
-
-
void KstVector::newSync() {
NumNew = NumShifted = 0;
}
-int KstVector::length() const {
- return _size;
-}
-
-
KstVectorPtr KstVector::generateVector(double x0, double x1, int n, const QString &tag) {
if (n < 2) {
n = 2;
--- trunk/extragear/graphics/kst/kst/kstvector.h #474574:474575
@@ -57,7 +57,7 @@
virtual ~KstVector();
public slots:
- virtual int length() const;
+ inline int length() const { return _size; }
/** Return V[i], interpolated/decimated to have ns_i total samples */
double interpolate(int i, int ns_i) const;
@@ -66,30 +66,30 @@
double value(int i);
/** Return Minimum value in Vector */
- double min() const;
+ inline double min() const { return _min; }
/** Return max value in Vector */
- double max() const;
+ inline double max() const { return _max; }
/** Return SpikeInsensitive max value in vector **/
- double ns_max() const { return _ns_max; }
+ inline double ns_max() const { return _ns_max; }
/** Return SpikeInsensitive min value in vector **/
- double ns_min() const { return _ns_min; }
+ inline double ns_min() const { return _ns_min; }
/** Return Mean value in Vector */
- double mean() const;
+ inline double mean() const { return _mean; }
/** Return Least Positive value in Vector */
- double minPos() const;
+ inline double minPos() const { return _minPos; }
/** Number of new samples in the vector since last newSync */
- int numNew() const;
+ inline int numNew() const { return NumNew; }
/** Number of samples shifted since last newSync */
- int numShift() const;
+ inline int numShift() const { return NumShifted; }
- bool isRising() const { return _is_rising; }
+ inline bool isRising() const { return _is_rising; }
/** reset New Samples and Shifted samples */
void newSync();
@@ -186,6 +186,8 @@
this is false. */
bool _editable : 1;
+ double _min, _max, _mean, _minPos;
+
/** Possibly null. Be careful, this is non-standard usage of a KstShared.
* The purpose of this is to trigger hierarchical updates properly.
*/
More information about the Kst
mailing list