hpp-fcl  1.7.4
HPP fork of FCL -- The Flexible Collision Library
timings.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2021 INRIA
3 //
4 
5 #ifndef HPP_FCL_TIMINGS_FWD_H
6 #define HPP_FCL_TIMINGS_FWD_H
7 
8 #include "hpp/fcl/fwd.hh"
9 
10 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
11  #include <chrono>
12 #endif
13 
14 namespace hpp { namespace fcl {
15 
16  struct CPUTimes
17  {
18  double wall;
19  double user;
20  double system;
21 
23  : wall(0)
24  , user(0)
25  , system(0)
26  {}
27 
28  void clear()
29  {
30  wall = user = system = 0;
31  }
32 
33  };
34 
40  {
41 
43  : m_is_stopped(true)
44  {
45  start();
46  }
47 
48  CPUTimes elapsed() const
49  {
50  if(m_is_stopped)
51  return m_times;
52 
53  CPUTimes current(m_times);
54 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
55  std::chrono::time_point<std::chrono::steady_clock> current_clock = std::chrono::steady_clock::now();
56  current.user += static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(current_clock - m_start).count())*1e-3;
57 #endif
58  return current;
59  }
60 
61  void start()
62  {
63  if(m_is_stopped)
64  {
65  m_is_stopped = false;
66  m_times.clear();
67 
68 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
69  m_start = std::chrono::steady_clock::now();
70 #endif
71  }
72  }
73 
74  void stop()
75  {
76  if(m_is_stopped)
77  return;
78  m_is_stopped = true;
79 
80 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
81  m_end = std::chrono::steady_clock::now();
82  m_times.user += static_cast<double>(std::chrono::duration_cast<std::chrono::nanoseconds>(m_end - m_start).count())*1e-3;
83 #endif
84 
85  }
86 
87  void resume()
88  {
89 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
90  if(m_is_stopped)
91  m_start = std::chrono::steady_clock::now();
92 #endif
93  }
94 
95  bool is_stopped() const
96  {
97  return m_is_stopped;
98  }
99 
100  protected:
101 
104 
105 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
106  std::chrono::time_point<std::chrono::steady_clock> m_start, m_end;
107 #endif
108  };
109 
110 }}
111 
112 #endif // ifndef HPP_FCL_TIMINGS_FWD_H
double system
Definition: timings.h:20
CPUTimes()
Definition: timings.h:22
CPUTimes elapsed() const
Definition: timings.h:48
Main namespace.
Definition: AABB.h:43
void clear()
Definition: timings.h:28
bool is_stopped() const
Definition: timings.h:95
Definition: timings.h:16
CPUTimes m_times
Definition: timings.h:102
This class mimics the way "boost/timer/timer.hpp" operates while using the modern std::chrono library...
Definition: timings.h:39
bool m_is_stopped
Definition: timings.h:103
Timer()
Definition: timings.h:42
double user
Definition: timings.h:19
void stop()
Definition: timings.h:74
double wall
Definition: timings.h:18
void resume()
Definition: timings.h:87
void start()
Definition: timings.h:61
#define HPP_FCL_DLLAPI
Definition: config.hh:64