pinocchio  3.3.1
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
timer2.hpp
1 //
2 // Copyright (c) 2021 LAAS-CNRS
3 //
4 
5 #ifndef __pinocchio_utils_timer2_hpp__
6 #define __pinocchio_utils_timer2_hpp__
7 
8 #include <ctime>
9 
10 namespace pinocchio
11 {
12 
13  class Timer
14  {
15  public:
16  Timer()
17  {
18  clock_gettime(CLOCK_MONOTONIC, &start_);
19  }
20 
21  inline void reset()
22  {
23  clock_gettime(CLOCK_MONOTONIC, &start_);
24  }
25 
26  inline double get_duration()
27  {
28  clock_gettime(CLOCK_MONOTONIC, &finish_);
29  duration_ = static_cast<double>(finish_.tv_sec - start_.tv_sec) * 1000000;
30  duration_ += static_cast<double>(finish_.tv_nsec - start_.tv_nsec) / 1000;
31  return duration_ / 1000.;
32  }
33 
34  inline double get_us_duration()
35  {
36  clock_gettime(CLOCK_MONOTONIC, &finish_);
37  duration_ = static_cast<double>(finish_.tv_sec - start_.tv_sec) * 1000000;
38  duration_ += static_cast<double>(finish_.tv_nsec - start_.tv_nsec) / 1000;
39  return duration_;
40  }
41 
42  private:
43  struct timespec start_;
44  struct timespec finish_;
45  double duration_;
46  };
47 } // namespace pinocchio
48 
49 #endif
Main pinocchio namespace.
Definition: treeview.dox:11