hpp-fcl 2.2.0
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 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 Timer() : m_is_stopped(true) { start(); }
34
35 CPUTimes elapsed() const {
36 if (m_is_stopped) return m_times;
37
38 CPUTimes current(m_times);
39#ifdef HPP_FCL_WITH_CXX11_SUPPORT
40 std::chrono::time_point<std::chrono::steady_clock> current_clock =
41 std::chrono::steady_clock::now();
42 current.user += static_cast<double>(
43 std::chrono::duration_cast<std::chrono::nanoseconds>(
44 current_clock - m_start)
45 .count()) *
46 1e-3;
47#endif
48 return current;
49 }
50
51 void start() {
52 if (m_is_stopped) {
53 m_is_stopped = false;
54 m_times.clear();
55
56#ifdef HPP_FCL_WITH_CXX11_SUPPORT
57 m_start = std::chrono::steady_clock::now();
58#endif
59 }
60 }
61
62 void stop() {
63 if (m_is_stopped) return;
64 m_is_stopped = true;
65
66#ifdef HPP_FCL_WITH_CXX11_SUPPORT
67 m_end = std::chrono::steady_clock::now();
68 m_times.user += static_cast<double>(
69 std::chrono::duration_cast<std::chrono::nanoseconds>(
70 m_end - m_start)
71 .count()) *
72 1e-3;
73#endif
74 }
75
76 void resume() {
77#ifdef HPP_FCL_WITH_CXX11_SUPPORT
78 if (m_is_stopped) m_start = std::chrono::steady_clock::now();
79#endif
80 }
81
82 bool is_stopped() const { return m_is_stopped; }
83
84 protected:
87
88#ifdef HPP_FCL_WITH_CXX11_SUPPORT
89 std::chrono::time_point<std::chrono::steady_clock> m_start, m_end;
90#endif
91};
92
93} // namespace fcl
94} // namespace hpp
95
96#endif // ifndef HPP_FCL_TIMINGS_FWD_H
#define HPP_FCL_DLLAPI
Definition: config.hh:64
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:51
CPUTimes m_times
Definition: timings.h:85
Timer()
Definition: timings.h:33
void stop()
Definition: timings.h:62
bool is_stopped() const
Definition: timings.h:82
CPUTimes elapsed() const
Definition: timings.h:35
void resume()
Definition: timings.h:76
bool m_is_stopped
Definition: timings.h:86