1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "cc/test/lap_timer.h"
7 #include "base/logging.h"
11 LapTimer::LapTimer(int warmup_laps
,
12 base::TimeDelta time_limit
,
14 : warmup_laps_(warmup_laps
),
15 time_limit_(time_limit
),
16 check_interval_(check_interval
) {
17 DCHECK_GT(check_interval
, 0);
21 void LapTimer::Reset() {
22 accumulator_
= base::TimeDelta();
25 remaining_warmups_
= warmup_laps_
;
29 void LapTimer::Start() { start_time_
= base::TimeTicks::HighResNow(); }
31 bool LapTimer::IsWarmedUp() { return remaining_warmups_
<= 0; }
33 void LapTimer::NextLap() {
42 accumulated_
= (num_laps_
% check_interval_
) == 0;
44 base::TimeTicks now
= base::TimeTicks::HighResNow();
45 accumulator_
+= now
- start_time_
;
50 bool LapTimer::HasTimeLimitExpired() { return accumulator_
>= time_limit_
; }
52 float LapTimer::MsPerLap() {
54 return accumulator_
.InMillisecondsF() / num_laps_
;
57 float LapTimer::LapsPerSecond() {
59 return num_laps_
/ accumulator_
.InSecondsF();
62 int LapTimer::NumLaps() { return num_laps_
; }