mal-packet-weaver
C++20 packet serialization/deserialization library.
Loading...
Searching...
No Matches
timer.hpp
Go to the documentation of this file.
1
#pragma once
7
namespace
mal_toolkit
8
{
15
template
<
class
clock>
16
class
Timer
17
{
18
public
:
22
Timer
()
23
{
24
current_
= clock::now();
25
reset
();
26
}
27
31
void
reset_to_now
() {
start_
= clock::now(); }
32
36
void
reset
() {
start_
=
current_
; }
37
43
constexpr
float
elapsed
() noexcept
44
{
45
current_
= clock::now();
46
return
std::chrono::duration_cast<std::chrono::duration<float>>(
current_
-
start_
).count();
47
}
48
49
private
:
50
std::chrono::time_point<clock>
start_
;
51
std::chrono::time_point<clock>
current_
;
52
};
53
57
using
SteadyTimer
=
Timer<std::chrono::steady_clock>
;
58
62
using
HighResolutionTimer
=
Timer<std::chrono::high_resolution_clock>
;
63
64
}
// namespace mal_toolkit
mal_toolkit::Timer
A simple timer class for measuring elapsed time using various clock types.
Definition
timer.hpp:17
mal_toolkit::Timer::start_
std::chrono::time_point< clock > start_
The time point representing the start time.
Definition
timer.hpp:50
mal_toolkit::Timer::elapsed
constexpr float elapsed() noexcept
Calculates and returns the elapsed time since the timer was last reset.
Definition
timer.hpp:43
mal_toolkit::Timer::reset
void reset()
Resets the start time to the previously captured current time.
Definition
timer.hpp:36
mal_toolkit::Timer::Timer
Timer()
Constructs a Timer and initializes it with the current time.
Definition
timer.hpp:22
mal_toolkit::Timer::current_
std::chrono::time_point< clock > current_
The time point representing the current time.
Definition
timer.hpp:51
mal_toolkit::Timer::reset_to_now
void reset_to_now()
Resets the start time to the current time.
Definition
timer.hpp:31
mal_toolkit
Contains a collection of tools and utilities provided by the MAL Toolkit library.
Definition
backoffs.hpp:7
third_party
mal-toolkit
mal-toolkit
mal-toolkit
timer.hpp
Generated on Sun Jul 14 2024 00:02:52 for mal-packet-weaver by
1.11.0