AGX Dynamics 2.42.2.1
Loading...
Searching...
No Matches
HighAccuracyTimer.h
Go to the documentation of this file.
1/*
2Copyright 2007-2025. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19#include <agx/agxCore_export.h>
20#include <agx/Integer.h>
21
22#include <agx/agx.h>
23
24#include <chrono>
25
26
27
28namespace agx {
29
38 {
39 public:
40
45 HighAccuracyTimer(bool startImmediately = false);
46
51 void start();
52
58 void stop();
59
63 void reset(bool startAfterReset = false);
64
69 Real64 getTime() const;
70
72 bool isRunning() const;
73
74 private:
75 using time_point = std::chrono::high_resolution_clock::time_point;
76 using duration = std::chrono::duration<agx::Real64, std::milli>;
77
78 time_point m_start;
79 duration m_total;
80
81 bool m_running;
82 };
83
84
85 /* Implementation */
86 inline HighAccuracyTimer::HighAccuracyTimer(bool startImmediately)
87 {
88 reset();
89 if (startImmediately)
90 this->start();
91 }
92
93
95 {
96 if (m_running)
97 return;
98
99 m_running = true;
100
101 m_start = std::chrono::high_resolution_clock::now();
102 }
103
104
106 {
107 if (m_running) {
108 m_running = false;
109
110 time_point end = std::chrono::high_resolution_clock::now();
111 duration elapsed = end - m_start;
112 m_total += elapsed;
113 }
114 }
115
116
118 {
119 m_total = duration::zero();
120
121 m_running = false;
122 if (startAfterReset)
123 this->start();
124 }
125
126
128 {
129 return m_running;
130 }
131
132
134 {
135 if (m_running)
136 {
137 time_point now = std::chrono::high_resolution_clock::now();
138 duration elapsed = now - m_start;
139 duration total = m_total + elapsed;
140 return total.count();
141 }
142 else
143 {
144 return m_total.count();
145 }
146 }
147
148
149} // namespace agx
#define AGXCORE_EXPORT
The HighAccurayTimer class can replace the regular Timer class in high level applications where the n...
Real64 getTime() const
Report total elapsed time since start in milliseconds, excluding intervals when the timer was suspend...
void start()
Starts the HighAccuracyTimer.
bool isRunning() const
Return true if running.
void reset(bool startAfterReset=false)
Clear all data and optionally restart the timer.
HighAccuracyTimer(bool startImmediately=false)
Creates a HighAccuracyTimer.
void stop()
Stops the HighAccuracyTimer.
#define AGX_FORCE_INLINE
Definition: macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.
double Real64
Definition: Real.h:44
LinearProbingHashSetImplementation< KeyT, HashT >::iterator end(LinearProbingHashSetImplementation< KeyT, HashT > &set)