blob: 192366aef8ea927223864004f038188d58451693 [file] [log] [blame]
pbos@webrtc.orgaf8d5af2013-07-09 08:02:331/*
2 * Copyright (c) 2013 The WebRTC project authors. All Rights Reserved.
3 *
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
6 * tree. An additional intellectual property rights grant can be found
7 * in the file PATENTS. All contributing project authors may
8 * be found in the AUTHORS file in the root of the source tree.
9 */
Mirko Bonadei92ea95e2017-09-15 04:47:3110#include "test/statistics.h"
pbos@webrtc.orgaf8d5af2013-07-09 08:02:3311
12#include <math.h>
13
Sergey Silkin3be2a552018-01-17 14:11:4414#include <algorithm>
15
pbos@webrtc.orgaf8d5af2013-07-09 08:02:3316namespace webrtc {
17namespace test {
18
Sergey Silkin3be2a552018-01-17 14:11:4419Statistics::Statistics()
20 : sum_(0.0),
21 sum_squared_(0.0),
22 max_(std::numeric_limits<double>::min()),
23 min_(std::numeric_limits<double>::max()),
24 count_(0) {}
pbos@webrtc.orgaf8d5af2013-07-09 08:02:3325
26void Statistics::AddSample(double sample) {
27 sum_ += sample;
28 sum_squared_ += sample * sample;
Sergey Silkin3be2a552018-01-17 14:11:4429 max_ = std::max(max_, sample);
30 min_ = std::min(min_, sample);
pbos@webrtc.orgaf8d5af2013-07-09 08:02:3331 ++count_;
32}
33
Sergey Silkin3be2a552018-01-17 14:11:4434double Statistics::Max() const {
35 return max_;
36}
37
pbos@webrtc.orgaf8d5af2013-07-09 08:02:3338double Statistics::Mean() const {
39 if (count_ == 0)
40 return 0.0;
41 return sum_ / count_;
42}
43
Sergey Silkin3be2a552018-01-17 14:11:4444double Statistics::Min() const {
45 return min_;
46}
47
pbos@webrtc.orgaf8d5af2013-07-09 08:02:3348double Statistics::Variance() const {
49 if (count_ == 0)
50 return 0.0;
51 return sum_squared_ / count_ - Mean() * Mean();
52}
53
54double Statistics::StandardDeviation() const {
55 return sqrt(Variance());
56}
57} // namespace test
58} // namespace webrtc