hpp-fcl  1.7.1
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 
54  CPUTimes current(m_times);
55 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
56  std::chrono::time_point<std::chrono::steady_clock> current_clock = std::chrono::steady_clock::now();
57  current.user += std::chrono::duration_cast<std::chrono::nanoseconds>(current_clock - m_start).count()*1e-3;
58 #endif
59  return current;
60  }
61 
62  void start()
63  {
64  if(m_is_stopped)
65  {
66  m_is_stopped = false;
67  m_times.clear();
68 
69 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
70  m_start = std::chrono::steady_clock::now();
71 #endif
72  }
73  }
74 
75  void stop()
76  {
77  if(m_is_stopped)
78  return;
79  m_is_stopped = true;
80 
81 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
82  m_end = std::chrono::steady_clock::now();
83  m_times.user += std::chrono::duration_cast<std::chrono::nanoseconds>(m_end - m_start).count()*1e-3;
84 #endif
85 
86  }
87 
88  void resume()
89  {
90 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
91  if(m_is_stopped)
92  m_start = std::chrono::steady_clock::now();
93 #endif
94  }
95 
96  bool is_stopped() const
97  {
98  return m_is_stopped;
99  }
100 
101  protected:
102 
105 
106 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
107  std::chrono::time_point<std::chrono::steady_clock> m_start, m_end;
108 #endif
109  };
110 
111 }}
112 
113 #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:96
Definition: timings.h:16
CPUTimes m_times
Definition: timings.h:103
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:104
Timer()
Definition: timings.h:42
double user
Definition: timings.h:19
void stop()
Definition: timings.h:75
double wall
Definition: timings.h:18
void resume()
Definition: timings.h:88
void start()
Definition: timings.h:62
#define HPP_FCL_DLLAPI
Definition: config.hh:64