timer2.hpp
Go to the documentation of this file.
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:
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
pinocchio::Timer::Timer
Timer()
Definition: timer2.hpp:16
pinocchio::Timer::start_
struct timespec start_
Definition: timer2.hpp:43
pinocchio::Timer
Definition: timer2.hpp:13
pinocchio::Timer::reset
void reset()
Definition: timer2.hpp:21
pinocchio::Timer::duration_
double duration_
Definition: timer2.hpp:45
pinocchio::Timer::finish_
struct timespec finish_
Definition: timer2.hpp:44
pinocchio::Timer::get_duration
double get_duration()
Definition: timer2.hpp:26
pinocchio::Timer::get_us_duration
double get_us_duration()
Definition: timer2.hpp:34
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:12