libzed 1.9.9
A general-purpose library for quick and simple data manipulation.
 
Loading...
Searching...
No Matches
timer.hpp
1#pragma once
2
3#include <chrono>
4
5#ifdef __has_include
6#if __has_include(<cereal/cereal.hpp>)
7#include <cereal/cereal.hpp>
8#endif
9#endif
10
11namespace z {
12namespace core {
19class timer {
20private:
21 std::chrono::high_resolution_clock::time_point start;
22
23public:
30 timer(bool run = true) noexcept;
31
36
41
48 unsigned int micros() const noexcept;
49
56 unsigned int millis() const noexcept;
57
64 unsigned int seconds() const noexcept;
65
72 unsigned int minutes() const noexcept;
73
80 unsigned int hours() const noexcept;
81
82#ifdef __has_include
83#if __has_include(<cereal/cereal.hpp>)
88 template <class Archive>
89 void save(Archive &ar) const {
92 }
93
98 template <class Archive>
99 void load(Archive &ar) {
102 reset(std::chrono::high_resolution_clock::now() - std::chrono::microseconds(elapsed));
103 }
104#endif
105#endif
106};
107} // namespace core
108} // namespace z
A wrapper for std::vector.
Definition array.hpp:72
A class for easily managing timers.
Definition timer.hpp:19
unsigned int hours() const noexcept
Get the elapsed time in minutes.
unsigned int millis() const noexcept
Get the elapsed time in milliseconds.
void save(Archive &ar) const
Serialization output.
Definition timer.hpp:89
void reset() noexcept
Reset the timer.
timer(bool run=true) noexcept
Timer constructor.
unsigned int seconds() const noexcept
Get the elapsed time in seconds.
unsigned int micros() const noexcept
Get the elapsed time in microseconds.
void load(Archive &ar)
Serialization input.
Definition timer.hpp:99
unsigned int minutes() const noexcept
Get the elapsed time in minutes.