1 #ifndef BENCHMARK_THREAD_TIMER_H
2 #define BENCHMARK_THREAD_TIMER_H
12 ThreadTimer() = default;
14 // Called by each thread
17 start_real_time_
= ChronoClockNow();
18 start_cpu_time_
= ThreadCPUUsage();
21 // Called by each thread
25 real_time_used_
+= ChronoClockNow() - start_real_time_
;
26 // Floating point error can result in the subtraction producing a negative
27 // time. Guard against that.
28 cpu_time_used_
+= std::max
<double>(ThreadCPUUsage() - start_cpu_time_
, 0);
31 // Called by each thread
32 void SetIterationTime(double seconds
) { manual_time_used_
+= seconds
; }
34 bool running() const { return running_
; }
36 // REQUIRES: timer is not running
37 double real_time_used() {
39 return real_time_used_
;
42 // REQUIRES: timer is not running
43 double cpu_time_used() {
45 return cpu_time_used_
;
48 // REQUIRES: timer is not running
49 double manual_time_used() {
51 return manual_time_used_
;
55 bool running_
= false; // Is the timer running
56 double start_real_time_
= 0; // If running_
57 double start_cpu_time_
= 0; // If running_
59 // Accumulated time so far (does not contain current slice if running_)
60 double real_time_used_
= 0;
61 double cpu_time_used_
= 0;
62 // Manually set iteration time. User sets this with SetIterationTime(seconds).
63 double manual_time_used_
= 0;
66 } // namespace internal
67 } // namespace benchmark
69 #endif // BENCHMARK_THREAD_TIMER_H