forked from RobotLocomotion/drake
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimer.h
46 lines (35 loc) · 1.17 KB
/
timer.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once
// TODO(#16486): Remove chrono include by encapsulating into timer.cc
#include <chrono>
#include "drake/common/drake_copyable.h"
/// @file
/// Provides drake::Timer interface and drake::SteadyTimer for timing events.
namespace drake {
/// Abstract base class for timing utility.
class Timer {
public:
/// Properly implemented Timers must start timing upon construction.
Timer() = default;
virtual ~Timer() = default;
/// Begins timing. Call Start everytime you want to reset the timer to zero.
virtual void Start() = 0;
/// Obtains a timer measurement in seconds.
/// Call this repeatedly to get multiple measurements.
/// @return the amount of time since the timer started.
virtual double Tick() = 0;
protected:
DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN(Timer) // protected from slicing
};
/// Implementation of timing utility that uses monotonic
/// std::chrono::steady_clock.
class SteadyTimer final : public Timer {
public:
DRAKE_DEFAULT_COPY_AND_MOVE_AND_ASSIGN(SteadyTimer)
SteadyTimer();
void Start() final;
double Tick() final;
private:
using clock = std::chrono::steady_clock;
clock::time_point start_time_;
};
} // namespace drake