[Kst] kdeextragear-2/kst/kst
Barth Netterfield
netterfield at astro.utoronto.ca
Tue Jul 15 22:58:45 CEST 2003
CVS commit by netterfield:
Use local variables for math in kstvector::update.
84% cpu to 30% cpu in one benchmark....
M +27 -22 kstvector.cpp 1.35
--- kdeextragear-2/kst/kst/kstvector.cpp #1.34:1.35
@@ -209,4 +209,5 @@ void KstVector::resize(int sz) {
KstObject::UpdateType KstVector::update(int update_counter) {
int i;
+ double max, min, sum, sum2, minpos, v;
if (KstObject::checkUpdateCounter(update_counter))
@@ -218,32 +219,36 @@ KstObject::UpdateType KstVector::update(
/* Do Nothing */ ;
- _scalars["max"]->setValue(_v[i]);
- _scalars["min"]->setValue(_v[i]);
- _scalars["sum"]->setValue(_v[i]);
- _scalars["sumsquared"]->setValue(_v[i]*_v[i]);
+ max = min = sum = sum2 = _v[i];
+ if (_v[i]>0)
+ minpos = _v[i];
+ else
+ minpos = 1.0E300;
+
+ //_scalars["max"]->setValue(_v[i]);
+ //_scalars["min"]->setValue(_v[i]);
+
for (; i < _size; i++) {
- if (finite(_v[i])) {
+ v = _v[i]; // get rid of redirections
+ if (finite(v)) {
_nsum++;
- _scalars["sum"]->setValue(_scalars["sum"]->value() + _v[i]);
- _scalars["sumsquared"]->setValue(_scalars["sumsquared"]->value() + _v[i]*_v[i]);
- if (_scalars["max"]->value() < _v[i])
- _scalars["max"]->setValue(_v[i]);
- if (_scalars["min"]->value() > _v[i])
- _scalars["min"]->setValue(_v[i]);
- }
- }
+ sum += v;
+ sum2 += v*v;
- if (_scalars["min"]->value() > 0) {
- _scalars["minpos"]->setValue(_scalars["min"]->value());
- } else if (_scalars["max"]->value() > 0) {
- _scalars["minpos"]->setValue(_scalars["max"]->value());
- for (i = 0; i < _size; i++) {
- if (finite(_v[i]) && _scalars["minpos"]->value() > _v[i]) {
- _scalars["minpos"]->setValue(_v[i]);
+ if (v>max)
+ max = v;
+ else {
+ if (v<min)
+ min = v;
+ if (v<minpos)
+ if (v>0)
+ minpos = v;
}
}
- } else {
- _scalars["minpos"]->setValue(1.0E300);
}
+ _scalars["sum"]->setValue(sum);
+ _scalars["sumsquared"]->setValue(sum2);
+ _scalars["max"]->setValue(max);
+ _scalars["min"]->setValue(min);
+ _scalars["minpos"]->setValue(minpos);
UpdateScalars();
More information about the Kst
mailing list