43 template<
typename TimeUnit = std::chrono::milliseconds>
49 using TimePoint = std::chrono::time_point<ChronoClock>;
67 explicit Timer(
const std::string& inName) :
93 std::this_thread::sleep_for(TimeUnit(length));
102 start_ = ChronoClock::now();
115 const auto duration = std::chrono::duration_cast<TimeUnit>(ChronoClock::now() - start_);
119 std::cout << name_ <<
"Elapsed Time = " << duration.count() << unit_ << std::endl;
127 std::string name_{
"" };
128 std::string unit_{
"" };
133 if constexpr (std::is_same_v<TimeUnit, std::chrono::hours>)
137 else if constexpr (std::is_same_v<TimeUnit, std::chrono::minutes>)
141 else if constexpr (std::is_same_v<TimeUnit, std::chrono::seconds>)
145 else if constexpr (std::is_same_v<TimeUnit, std::chrono::milliseconds>)
147 unit_ =
" milliseconds";
149 else if constexpr (std::is_same_v<TimeUnit, std::chrono::microseconds>)
151 unit_ =
" microseconds";
153 else if constexpr (std::is_same_v<TimeUnit, std::chrono::nanoseconds>)
155 unit_ =
" nanoseconds";
159 unit_ =
" time units of some sort";
A timer class for timing code execution.
Definition: Timer.hpp:45
std::chrono::time_point< ChronoClock > TimePoint
Definition: Timer.hpp:49
std::chrono::steady_clock ChronoClock
Definition: Timer.hpp:48
void tic() noexcept
Definition: Timer.hpp:100
Timer(const std::string &inName)
Definition: Timer.hpp:67
Timer()
Definition: Timer.hpp:55
void setName(const std::string &inName)
Definition: Timer.hpp:80
void sleep(uint32 length)
Definition: Timer.hpp:91
TimeUnit toc(PrintElapsedTime printElapsedTime=PrintElapsedTime::YES)
Definition: Timer.hpp:113
Definition: Cartesian.hpp:40
PrintElapsedTime
Print Elapsed Time boolean.
Definition: Enums.hpp:110
std::uint32_t uint32
Definition: Types.hpp:40