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
7namespace mal_toolkit
8{
15 template <class clock>
16 class Timer
17 {
18 public:
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
58
63
64} // namespace mal_toolkit
A simple timer class for measuring elapsed time using various clock types.
Definition timer.hpp:17
std::chrono::time_point< clock > start_
The time point representing the start time.
Definition timer.hpp:50
constexpr float elapsed() noexcept
Calculates and returns the elapsed time since the timer was last reset.
Definition timer.hpp:43
void reset()
Resets the start time to the previously captured current time.
Definition timer.hpp:36
Timer()
Constructs a Timer and initializes it with the current time.
Definition timer.hpp:22
std::chrono::time_point< clock > current_
The time point representing the current time.
Definition timer.hpp:51
void reset_to_now()
Resets the start time to the current time.
Definition timer.hpp:31
Contains a collection of tools and utilities provided by the MAL Toolkit library.
Definition backoffs.hpp:7