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