Dura2D  v0.1.0
An educational 2D game physics library
Loading...
Searching...
No Matches
d2Timer.h
Go to the documentation of this file.
1#ifndef D2TIMER_H
2#define D2TIMER_H
3
4#include <chrono>
5#include <iostream>
6
7class d2Timer
8{
9public:
11 {
12 start();
13 }
14
16 {
17 stop();
18 std::cout << "Duration: " << getDuration() << " ns" << std::endl;
19 }
20
21 void start()
22 {
23 m_start = std::chrono::high_resolution_clock::now();
24 }
25
26 void stop()
27 {
28 auto end = std::chrono::high_resolution_clock::now();
29 m_duration = std::chrono::duration_cast<std::chrono::nanoseconds>(end - m_start);
30 }
31
32 [[nodiscard]]
33 long long getDuration() const
34 {
35 return m_duration.count();
36 }
37
38private:
39 std::chrono::high_resolution_clock::time_point m_start { };
40 std::chrono::nanoseconds m_duration { 0 };
41};
42
43#endif //D2TIMER_H
Definition d2Timer.h:8
void start()
Definition d2Timer.h:21
~d2Timer()
Definition d2Timer.h:15
long long getDuration() const
Definition d2Timer.h:33
void stop()
Definition d2Timer.h:26
d2Timer()
Definition d2Timer.h:10