@@ -269,7 +269,8 @@ void chaser_check::do_update(object_key channel, uint64_t speed,
269269 }
270270
271271 // Integer to floating point.
272- speeds_[channel] = to_floating (speed);
272+ const auto fast = to_floating (speed);
273+ speeds_[channel] = fast;
273274
274275 // Three elements are required to measure deviation, don't drop below.
275276 const auto count = speeds_.size ();
@@ -279,34 +280,31 @@ void chaser_check::do_update(object_key channel, uint64_t speed,
279280 return ;
280281 }
281282
282- const auto rate = std::accumulate (speeds_.begin (), speeds_.end (), 0.0 ,
283- [](double sum, const auto & element) NOEXCEPT
284- {
285- return sum + element.second ;
286- });
283+ double sum = 0.0 ;
284+ double sum_squares = 0.0 ;
285+ for (const auto & element : speeds_)
286+ {
287+ sum += element.second ;
288+ sum_squares += std::pow (element.second , two);
289+ }
287290
288- const auto mean = rate / count;
289- if (speed >= mean)
291+ const auto mean = sum / count;
292+ if (fast >= mean)
290293 {
291294 handler (error::success);
292295 return ;
293296 }
294297
295- const auto variance = std::accumulate (speeds_.begin (), speeds_.end (), 0.0 ,
296- [mean](double sum, const auto & element) NOEXCEPT
297- {
298- return sum + std::pow (element.second - mean, two);
299- }) / (sub1 (count));
300-
298+ const auto variance = (sum_squares - (sum * sum) / count) / sub1 (count);
301299 const auto sdev = std::sqrt (variance);
302- const auto slow = (mean - speed ) > (allowed_deviation_ * sdev);
300+ const auto slow = (mean - fast ) > (allowed_deviation_ * sdev);
303301
304302 // Only speed < mean channels are logged.
305303 LOGV (" Below average channel (" << count << " ) rate ("
306- << to_kilobits_per_second (rate) << " ) mean ("
304+ << to_kilobits_per_second (sum) << " ) mean ("
307305 << to_kilobits_per_second (mean) << " ) sdev ("
308306 << to_kilobits_per_second (sdev) << " ) Kbps [" << (slow ? " *" : " " )
309- << to_kilobits_per_second (to_floating (speed) ) << " ]." );
307+ << to_kilobits_per_second (fast ) << " ]." );
310308
311309 if (slow)
312310 {
0 commit comments