OLD | NEW |
(Empty) | |
| 1 /* |
| 2 * Copyright (c) 2016 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 */ |
| 10 |
| 11 #include "webrtc/modules/audio_processing/test/performance_timer.h" |
| 12 |
| 13 #include <math.h> |
| 14 |
| 15 #include <numeric> |
| 16 |
| 17 #include "webrtc/base/checks.h" |
| 18 |
| 19 namespace webrtc { |
| 20 namespace test { |
| 21 |
| 22 PerformanceTimer::PerformanceTimer(int num_frames_to_process) |
| 23 : clock_(webrtc::Clock::GetRealTimeClock()) { |
| 24 timestamps_us_.reserve(num_frames_to_process); |
| 25 } |
| 26 |
| 27 PerformanceTimer::~PerformanceTimer() = default; |
| 28 |
| 29 void PerformanceTimer::StartTimer() { |
| 30 start_timestamp_us_ = rtc::Optional<int64_t>(clock_->TimeInMicroseconds()); |
| 31 } |
| 32 |
| 33 void PerformanceTimer::StopTimer() { |
| 34 RTC_DCHECK(start_timestamp_us_); |
| 35 timestamps_us_.push_back(clock_->TimeInMicroseconds() - *start_timestamp_us_); |
| 36 } |
| 37 |
| 38 double PerformanceTimer::GetDurationAverage() const { |
| 39 RTC_DCHECK(!timestamps_us_.empty()); |
| 40 return static_cast<double>( |
| 41 std::accumulate(timestamps_us_.begin(), timestamps_us_.end(), 0)) / |
| 42 timestamps_us_.size(); |
| 43 } |
| 44 |
| 45 double PerformanceTimer::GetDurationStandardDeviation() const { |
| 46 RTC_DCHECK(!timestamps_us_.empty()); |
| 47 double average_duration = GetDurationAverage(); |
| 48 |
| 49 double variance = std::accumulate( |
| 50 timestamps_us_.begin(), timestamps_us_.end(), 0.0, |
| 51 [average_duration](const double& a, const int64_t& b) { |
| 52 return a + (b - average_duration) * (b - average_duration); |
| 53 }); |
| 54 |
| 55 return sqrt(variance / timestamps_us_.size()); |
| 56 } |
| 57 |
| 58 } // namespace test |
| 59 } // namespace webrtc |
OLD | NEW |