timings.h
Go to the documentation of this file.
1 //
2 // Copyright (c) 2021-2023 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 {
15 namespace fcl {
16 
17 struct CPUTimes {
18  double wall;
19  double user;
20  double system;
21 
22  CPUTimes() : wall(0), user(0), system(0) {}
23 
24  void clear() { wall = user = system = 0; }
25 };
26 
32 struct HPP_FCL_DLLAPI Timer {
33 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
34  typedef std::chrono::steady_clock clock_type;
35  typedef clock_type::duration duration_type;
36 #endif
37 
42  Timer(const bool start_on_construction = true) : m_is_stopped(true) {
43  if (start_on_construction) Timer::start();
44  }
45 
46  CPUTimes elapsed() const {
47  if (m_is_stopped) return m_times;
48 
49  CPUTimes current(m_times);
50 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
51  std::chrono::time_point<std::chrono::steady_clock> current_clock =
52  std::chrono::steady_clock::now();
53  current.user += static_cast<double>(
54  std::chrono::duration_cast<std::chrono::nanoseconds>(
55  current_clock - m_start)
56  .count()) *
57  1e-3;
58 #endif
59  return current;
60  }
61 
62 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
63  duration_type duration() const { return (m_end - m_start); }
64 #endif
65 
66  void start() {
67  if (m_is_stopped) {
68  m_is_stopped = false;
69  m_times.clear();
70 
71 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
72  m_start = std::chrono::steady_clock::now();
73 #endif
74  }
75  }
76 
77  void stop() {
78  if (m_is_stopped) 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 += static_cast<double>(
84  std::chrono::duration_cast<std::chrono::nanoseconds>(
85  m_end - m_start)
86  .count()) *
87  1e-3;
88 #endif
89  }
90 
91  void resume() {
92 #ifdef HPP_FCL_WITH_CXX11_SUPPORT
93  if (m_is_stopped) {
94  m_start = std::chrono::steady_clock::now();
95  m_is_stopped = false;
96  }
97 #endif
98  }
99 
100  bool is_stopped() const { return m_is_stopped; }
101 
102  protected:
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 } // namespace fcl
112 } // namespace hpp
113 
114 #endif // ifndef HPP_FCL_TIMINGS_FWD_H
hpp::fcl::Timer::elapsed
CPUTimes elapsed() const
Definition: timings.h:46
hpp::fcl::Timer::resume
void resume()
Definition: timings.h:91
hpp::fcl::Timer::stop
void stop()
Definition: timings.h:77
hpp::fcl::Timer::start
void start()
Definition: timings.h:66
hpp::fcl::CPUTimes::clear
void clear()
Definition: timings.h:24
duration_type
clock_type::duration duration_type
Definition: obb.cpp:90
hpp::fcl::CPUTimes::system
double system
Definition: timings.h:20
hpp::fcl::CPUTimes::CPUTimes
CPUTimes()
Definition: timings.h:22
hpp::fcl::Timer::is_stopped
bool is_stopped() const
Definition: timings.h:100
hpp::fcl::Timer
This class mimics the way "boost/timer/timer.hpp" operates while using the modern std::chrono library...
Definition: timings.h:32
hpp::fcl::CPUTimes
Definition: timings.h:17
hpp
Main namespace.
Definition: broadphase_bruteforce.h:44
hpp::fcl::CPUTimes::user
double user
Definition: timings.h:19
hpp::fcl::Timer::m_is_stopped
bool m_is_stopped
Definition: timings.h:104
clock_type
std::chrono::high_resolution_clock clock_type
Definition: obb.cpp:89
hpp::fcl::Timer::Timer
Timer(const bool start_on_construction=true)
Default constructor for the timer.
Definition: timings.h:42
fwd.hh
hpp::fcl::CPUTimes::wall
double wall
Definition: timings.h:18
hpp::fcl::Timer::m_times
CPUTimes m_times
Definition: timings.h:103


hpp-fcl
Author(s):
autogenerated on Fri Aug 2 2024 02:45:15