2013-07-09 08:02:33 +00:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
|
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by a BSD-style license
|
|
|
|
|
* that can be found in the LICENSE file in the root of the source
|
|
|
|
|
* tree. An additional intellectual property rights grant can be found
|
|
|
|
|
* in the file PATENTS. All contributing project authors may
|
|
|
|
|
* be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
2017-09-15 06:47:31 +02:00
|
|
|
#include "test/statistics.h"
|
2013-07-09 08:02:33 +00:00
|
|
|
|
|
|
|
|
#include <math.h>
|
|
|
|
|
|
2018-01-17 15:11:44 +01:00
|
|
|
#include <algorithm>
|
|
|
|
|
|
2013-07-09 08:02:33 +00:00
|
|
|
namespace webrtc {
|
|
|
|
|
namespace test {
|
|
|
|
|
|
2018-01-17 15:11:44 +01:00
|
|
|
Statistics::Statistics()
|
|
|
|
|
: sum_(0.0),
|
|
|
|
|
sum_squared_(0.0),
|
|
|
|
|
max_(std::numeric_limits<double>::min()),
|
|
|
|
|
min_(std::numeric_limits<double>::max()),
|
|
|
|
|
count_(0) {}
|
2013-07-09 08:02:33 +00:00
|
|
|
|
|
|
|
|
void Statistics::AddSample(double sample) {
|
|
|
|
|
sum_ += sample;
|
|
|
|
|
sum_squared_ += sample * sample;
|
2018-01-17 15:11:44 +01:00
|
|
|
max_ = std::max(max_, sample);
|
|
|
|
|
min_ = std::min(min_, sample);
|
2013-07-09 08:02:33 +00:00
|
|
|
++count_;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 15:11:44 +01:00
|
|
|
double Statistics::Max() const {
|
|
|
|
|
return max_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-09 08:02:33 +00:00
|
|
|
double Statistics::Mean() const {
|
|
|
|
|
if (count_ == 0)
|
|
|
|
|
return 0.0;
|
|
|
|
|
return sum_ / count_;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-17 15:11:44 +01:00
|
|
|
double Statistics::Min() const {
|
|
|
|
|
return min_;
|
|
|
|
|
}
|
|
|
|
|
|
2013-07-09 08:02:33 +00:00
|
|
|
double Statistics::Variance() const {
|
|
|
|
|
if (count_ == 0)
|
|
|
|
|
return 0.0;
|
|
|
|
|
return sum_squared_ / count_ - Mean() * Mean();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
double Statistics::StandardDeviation() const {
|
|
|
|
|
return sqrt(Variance());
|
|
|
|
|
}
|
|
|
|
|
} // namespace test
|
|
|
|
|
} // namespace webrtc
|