hpp-fcl 2.4.4
HPP fork of FCL -- The Flexible Collision Library
Loading...
Searching...
No Matches
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
14namespace hpp {
15namespace fcl {
16
17struct 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
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
#define HPP_FCL_DLLAPI
Definition: config.hh:88
Main namespace.
Definition: broadphase_bruteforce.h:44
Definition: timings.h:17
double user
Definition: timings.h:19
double system
Definition: timings.h:20
CPUTimes()
Definition: timings.h:22
double wall
Definition: timings.h:18
void clear()
Definition: timings.h:24
This class mimics the way "boost/timer/timer.hpp" operates while using the modern std::chrono library...
Definition: timings.h:32
void start()
Definition: timings.h:66
CPUTimes m_times
Definition: timings.h:103
void stop()
Definition: timings.h:77
bool is_stopped() const
Definition: timings.h:100
CPUTimes elapsed() const
Definition: timings.h:46
void resume()
Definition: timings.h:91
Timer(const bool start_on_construction=true)
Default constructor for the timer.
Definition: timings.h:42
bool m_is_stopped
Definition: timings.h:104