robotoc
robotoc - efficient ROBOT Optimal Control solvers
Loading...
Searching...
No Matches
timer.hpp
Go to the documentation of this file.
1#ifndef ROBOTOC_UTILS_TIMER_HPP_
2#define ROBOTOC_UTILS_TIMER_HPP_
3
4#include <chrono>
5
6namespace robotoc {
7
12class Timer {
13public:
18 tick();
19 tick_ = tock_;
20 }
21
25 ~Timer() = default;
26
30 void tick() { tick_ = std::chrono::high_resolution_clock::now(); }
31
35 void tock() { tock_ = std::chrono::high_resolution_clock::now(); }
36
38
41 double s() const {
42 const std::chrono::duration<double, std::ratio<1, 1>> timing = tock_ - tick_;
43 return timing.count();
44 }
45
49 double ms() const {
50 const std::chrono::duration<double, std::milli> timing = tock_ - tick_;
51 return timing.count();
52 }
53
57 double ns() const {
58 const std::chrono::duration<double, std::nano> timing = tock_ - tick_;
59 return timing.count();
60 }
61
62private:
63 std::chrono::high_resolution_clock::time_point tick_, tock_;
64};
65
66} // namespace robotoc
67
68#endif // ROBOTOC_UTILS_TIMER_HPP_
A timer class to take benchmarks.
Definition: timer.hpp:12
double s() const
Returns the time duration (seconds) from tick() to tock().
Definition: timer.hpp:41
double ns() const
Returns the time duration (nano seconds) from tick() to tock().
Definition: timer.hpp:57
void tick()
Takes a time clock.
Definition: timer.hpp:30
void tock()
Takes a time clock.
Definition: timer.hpp:35
~Timer()=default
Default destructor.
Timer()
Default constructor.
Definition: timer.hpp:17
double ms() const
Returns the time duration (milli seconds) from tick() to tock().
Definition: timer.hpp:49
Definition: constraint_component_base.hpp:17