Git Product home page Git Product logo

os-chrono's Introduction

⏱️ golxzn::os::chrono ⏱️

Windows Ubuntu MacOS

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>
#include <golxzn/os/chrono.hpp>

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 fast_sys_elapsed{ test_clock(fast_clock<std::chrono::system_clock>{}) };
	const auto just_elapsed{     test_clock(clock{}) };
	const auto just_sys_elapsed{ test_clock(clock<std::chrono::system_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";
}

golxzh::os::chrono::timer examples

#include <iostream>
#include <golxzn/os/chrono.hpp>

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";
	} };

	while (timer.is_running()) {
		std::cout << "[" << std::this_thread::get_id() << "]: Time left: " << timer.time_left().milliseconds() << " milliseconds\n";
		std::this_thread::sleep_for(100ms);
	}

	std::cout << "[" << std::this_thread::get_id() << "] Exiting\n";

}

Thanks

Documentations is powered by:

os-chrono's People

Contributors

golxzn avatar

Stargazers

 avatar

Watchers

 avatar

os-chrono's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.