Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2016 The WebRTC project authors. All Rights Reserved. |
| 3 * | 3 * |
| 4 * Use of this source code is governed by a BSD-style license | 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 | 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 | 6 * tree. An additional intellectual property rights grant can be found |
| 7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
| 8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
| 9 */ | 9 */ |
| 10 | 10 |
| (...skipping 18 matching lines...) Expand all Loading... | |
| 29 void PerformanceTimer::StartTimer() { | 29 void PerformanceTimer::StartTimer() { |
| 30 start_timestamp_us_ = rtc::Optional<int64_t>(clock_->TimeInMicroseconds()); | 30 start_timestamp_us_ = rtc::Optional<int64_t>(clock_->TimeInMicroseconds()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 void PerformanceTimer::StopTimer() { | 33 void PerformanceTimer::StopTimer() { |
| 34 RTC_DCHECK(start_timestamp_us_); | 34 RTC_DCHECK(start_timestamp_us_); |
| 35 timestamps_us_.push_back(clock_->TimeInMicroseconds() - *start_timestamp_us_); | 35 timestamps_us_.push_back(clock_->TimeInMicroseconds() - *start_timestamp_us_); |
| 36 } | 36 } |
| 37 | 37 |
| 38 double PerformanceTimer::GetDurationAverage() const { | 38 double PerformanceTimer::GetDurationAverage() const { |
| 39 RTC_DCHECK(!timestamps_us_.empty()); | 39 return GetDurationAverage(0); |
| 40 return static_cast<double>( | |
| 41 std::accumulate(timestamps_us_.begin(), timestamps_us_.end(), 0)) / | |
| 42 timestamps_us_.size(); | |
| 43 } | 40 } |
| 44 | 41 |
| 45 double PerformanceTimer::GetDurationStandardDeviation() const { | 42 double PerformanceTimer::GetDurationStandardDeviation() const { |
| 46 RTC_DCHECK(!timestamps_us_.empty()); | 43 return GetDurationStandardDeviation(0); |
| 47 double average_duration = GetDurationAverage(); | 44 } |
| 45 | |
| 46 double PerformanceTimer::GetDurationAverage( | |
| 47 int number_of_warmup_samples) const { | |
|
hlundin-webrtc
2017/03/17 14:16:37
This should be a size_t, imo.
ivoc
2017/03/17 15:14:47
Done.
| |
| 48 const int number_of_samples = | |
|
hlundin-webrtc
2017/03/17 14:16:37
RTC_DCHECK_GT(timestamps_us_.size(), number_of_war
ivoc
2017/03/17 15:14:47
Done.
| |
| 49 timestamps_us_.size() - number_of_warmup_samples; | |
| 50 RTC_DCHECK_GT(number_of_samples, 0); | |
|
hlundin-webrtc
2017/03/17 14:16:36
... and skip this.
ivoc
2017/03/17 15:14:47
Done.
| |
| 51 return static_cast<double>( | |
| 52 std::accumulate(timestamps_us_.begin() + number_of_warmup_samples, | |
| 53 timestamps_us_.end(), 0)) / | |
|
hlundin-webrtc
2017/03/17 14:16:37
Is it a problem that the initial value is an int l
ivoc
2017/03/17 15:14:47
Hmm, I think it makes sense to use int64_t's for t
| |
| 54 number_of_samples; | |
| 55 } | |
| 56 | |
| 57 double PerformanceTimer::GetDurationStandardDeviation( | |
|
hlundin-webrtc
2017/03/17 14:16:36
Essentially the same comments as above.
ivoc
2017/03/17 15:14:47
Done.
| |
| 58 int number_of_warmup_samples) const { | |
| 59 const int number_of_samples = | |
| 60 timestamps_us_.size() - number_of_warmup_samples; | |
| 61 RTC_DCHECK_GT(number_of_samples, 0); | |
| 62 double average_duration = GetDurationAverage(number_of_warmup_samples); | |
| 48 | 63 |
| 49 double variance = std::accumulate( | 64 double variance = std::accumulate( |
|
ivoc
2017/03/17 15:14:47
I used the same pattern of accumulating in int64_t
ivoc
2017/03/17 15:16:35
Oh, oops, that seems like a bad idea on second tho
| |
| 50 timestamps_us_.begin(), timestamps_us_.end(), 0.0, | 65 timestamps_us_.begin() + number_of_warmup_samples, timestamps_us_.end(), |
| 51 [average_duration](const double& a, const int64_t& b) { | 66 0.0, [average_duration](const double& a, const int64_t& b) { |
| 52 return a + (b - average_duration) * (b - average_duration); | 67 return a + (b - average_duration) * (b - average_duration); |
| 53 }); | 68 }); |
| 54 | 69 |
| 55 return sqrt(variance / timestamps_us_.size()); | 70 return sqrt(variance / number_of_samples); |
| 56 } | 71 } |
| 57 | 72 |
| 58 } // namespace test | 73 } // namespace test |
| 59 } // namespace webrtc | 74 } // namespace webrtc |
| OLD | NEW |