⏱️ golxzn::os::chrono ⏱️
Description
The time utilities for golxzn::os.
golxzn::os::chrono
contains of:
Each clock and timer has a template argument BaseClock
which has to have static method now()
returning time_point
. You could provide your own base clock to make clocks and timers work with your time point type. But ensure that your time point type has enough resolution to measure time. It has to be at least std::micro
.
Dependencies
This library requires golxzn::os::aliases and C++17 compatible compiler.
Usage
golxzh::os::chrono::clock
examples
#include <iostream>
int main() {
static const auto test_clock = [] (auto clock) {
size_t counter{};
while (counter != 1'000'000'000) ++counter;
return clock.elapsed();
};
using namespace golxzn::os::chrono;
const auto fast_elapsed{ test_clock(
fast_clock{}) };
const auto just_elapsed{ test_clock(
clock{}) };
std::cout << "Fast elapsed: " << fast_elapsed.milliseconds() << " milliseconds\n";
std::cout << "Just elapsed: " << just_elapsed.milliseconds() << " milliseconds\n";
std::cout << "Fast elapsed (sys): " << fast_sys_elapsed.milliseconds() << " milliseconds\n";
std::cout << "Just elapsed (sys): " << just_sys_elapsed.milliseconds() << " milliseconds\n";
}
Main header for golxzn::os::chrono.
Class that represents clock.In comparison with golxzn::os::chrono::fast_clock, it provides more funct...
Definition clock.hpp:68
Class that represents fast clock, which store only one time point.This class allows to measure time s...
Definition clock.hpp:39
golxzh::os::chrono::timer
examples
#include <iostream>
int main() {
using namespace std::chrono_literals;
std::cout << "[" << std::this_thread::get_id() << "]: Starting timer for 2 sec\n";
golxzn::chrono::timer
timer{ 1s, [] {
std::cout << "[" << std::this_thread::get_id() << "]: Timer done\n";
} };
std::this_thread::sleep_for(100ms);
}
std::cout << "[" << std::this_thread::get_id() << "] Exiting\n";
}
constexpr i32 milliseconds() const noexcept
Returns duration in milliseconds.
Class that represents timer.
Definition timer.hpp:60
time time_left() const noexcept
Returns time left to the end of the timer.
bool is_running() const noexcept
Returns true if timer is running.
Thanks
Documentations is powered by: