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 #ifndef CC_TEST_LAP_TIMER_H_
6 #define CC_TEST_LAP_TIMER_H_
8 #include "base/time/time.h"
12 // LapTimer is used to calculate average times per "Lap" in perf tests.
13 // Current() reports the time since the last call to Start().
14 // Store() adds the time since the last call to Start() to the accumulator, and
15 // resets the start time to now. Stored() returns the accumulated time.
16 // NextLap increments the lap counter, used in counting the per lap averages.
17 // If you initialize the LapTimer with a non zero warmup_laps, it will ignore
18 // the times for that many laps at the start.
19 // If you set the time_limit then you can use HasTimeLimitExpired() to see if
20 // the current accumulated time has crossed that threshold, with an optimization
21 // that it only tests this every check_interval laps.
24 LapTimer(int warmup_laps
, base::TimeDelta time_limit
, int check_interval
);
25 // Resets the timer back to it's starting state.
27 // Sets the start point to now.
29 // Returns true if there are no more warmup laps to do.
31 // Advance the lap counter and update the accumulated time.
32 // The accumulated time is only updated every check_interval laps.
33 // If accumulating then the start point will also be updated.
35 // Returns true if the stored time has exceeded the time limit specified.
36 // May cause a call to Store().
37 bool HasTimeLimitExpired();
38 // The average milliseconds per lap.
40 // The number of laps per second.
41 float LapsPerSecond();
42 // The number of laps recorded.
46 base::TimeTicks start_time_
;
47 base::TimeDelta accumulator_
;
50 int remaining_warmups_
;
51 base::TimeDelta time_limit_
;
55 DISALLOW_COPY_AND_ASSIGN(LapTimer
);
60 #endif // CC_TEST_LAP_TIMER_H_