blob: 0075d4c9a36347772249d8ba8d327d4581f29c3b [file] [log] [blame]
pbos@webrtc.org2f02da82013-07-09 08:02:33 +00001/*
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 */
pbos@webrtc.org24e20892013-10-28 16:32:01 +000010#include "webrtc/test/statistics.h"
pbos@webrtc.org2f02da82013-07-09 08:02:33 +000011
12#include <math.h>
13
14namespace webrtc {
15namespace test {
16
17Statistics::Statistics() : sum_(0.0), sum_squared_(0.0), count_(0) {}
18
19void Statistics::AddSample(double sample) {
20 sum_ += sample;
21 sum_squared_ += sample * sample;
22 ++count_;
23}
24
25double Statistics::Mean() const {
26 if (count_ == 0)
27 return 0.0;
28 return sum_ / count_;
29}
30
31double Statistics::Variance() const {
32 if (count_ == 0)
33 return 0.0;
34 return sum_squared_ / count_ - Mean() * Mean();
35}
36
37double Statistics::StandardDeviation() const {
38 return sqrt(Variance());
39}
40} // namespace test
41} // namespace webrtc