All Projects → andremaravilha → cxxtimer

andremaravilha / cxxtimer

Licence: MIT License
A timer for modern C++

Programming Languages

C++
36643 projects - #6 most used programming language
CMake
9771 projects

Projects that are alternatives of or similar to cxxtimer

chronoman
Utility class to simplify use of timers created by setTimeout
Stars: ✭ 15 (-31.82%)
Mutual labels:  timer, chrono
react-component-countdown-timer
This is a simple count down timer react component.
Stars: ✭ 18 (-18.18%)
Mutual labels:  timer
LiveSplitOne
A version of LiveSplit that works on a lot of platforms.
Stars: ✭ 172 (+681.82%)
Mutual labels:  timer
redtimer
RedTimer - Redmine Time Tracker
Stars: ✭ 59 (+168.18%)
Mutual labels:  timer
asynchronous
A D port of Python's asyncio library
Stars: ✭ 35 (+59.09%)
Mutual labels:  timer
vue-circular-count-down-timer
a count down timer library for vue.js
Stars: ✭ 45 (+104.55%)
Mutual labels:  timer
bestest timer
This is an awesome punch clock/timer plugin for Redmine. It's great. It's the bestest.
Stars: ✭ 15 (-31.82%)
Mutual labels:  timer
waves-timer-animation
A relaxing waves animation built with Jetpack Compose
Stars: ✭ 121 (+450%)
Mutual labels:  timer
custom timer
A Flutter package to create a customizable timer.
Stars: ✭ 25 (+13.64%)
Mutual labels:  timer
timerlab
⏰ A simple and customizable timer
Stars: ✭ 94 (+327.27%)
Mutual labels:  timer
gnome-shell-teatime
No description or website provided.
Stars: ✭ 34 (+54.55%)
Mutual labels:  timer
C-Sharp-Learning-Journey
Some of the projects i made when starting to learn c#, winfroms and wpf
Stars: ✭ 95 (+331.82%)
Mutual labels:  chronometer
advpl-MsgTimer
Função AdvPL de mensagens (Alert, Info, Stop, Success, YesNo e NoYes) com Timer para fechamento automático
Stars: ✭ 17 (-22.73%)
Mutual labels:  timer
pauseable.js
Create event emitters, intervals, and timeouts that can be paused and resumed.
Stars: ✭ 44 (+100%)
Mutual labels:  timer
goodtimer
Golang timer for humans.
Stars: ✭ 31 (+40.91%)
Mutual labels:  timer
alfred-timer-workflow
Alfred workflow to start a timer, which blinks when the time is up.
Stars: ✭ 39 (+77.27%)
Mutual labels:  timer
tm
timers and timeline
Stars: ✭ 31 (+40.91%)
Mutual labels:  timer
libmcu
A toolkit for firmware development
Stars: ✭ 33 (+50%)
Mutual labels:  timer
async-timer
Timer facilities for Rust's async story
Stars: ✭ 37 (+68.18%)
Mutual labels:  timer
countdown-vuejs
A Countdown Timer component for Vue.js
Stars: ✭ 58 (+163.64%)
Mutual labels:  timer

cxxtimer: A timer for modern C++

GitHub license Build Status Lines of code GitHub repo size

This is a header only C++ library that offers an easy-to-use Timer class.

You just need to include the header file cxxtimer.hpp and that's it. You can aready instantiate cxxtimer::Timer objects to time your C++ programs.

Quick Start

The code below shows how to use cxxtimer library.

#include <cxxtimer.hpp>
#include <iostream>
#include <string>

int main(int argc, char** argv) {

    // Instantiate cxxtimer::Timer object
    cxxtimer::Timer timer;
    
    // Start the timer
    timer.start();
    
    // Wait for the users
    std::string input_1;
    std::cout << "Please, type something and press ENTER to continue: ";
    std::getline(std::cin, input_1);
    
    // Stop/pause the timer
    timer.stop();
    
    // Get the elapsed time
    std::cout << "You took " << timer.count<std::chrono::seconds>() << " seconds." << std::endl;
    std::cout << "You took " << timer.count<std::chrono::milliseconds>() << " milliseconds." << std::endl;
    std::cout << "You took " << timer.count<std::chrono::nanoseconds>() << " nanoseconds." << std::endl;
    
    return 0;
}

The cxxtimer::Timer class can be resumed after stop/pause. You just need to call timer.start() again. Furthermore, you can reset the timer as well. For this, you can call the method timer.reset(). After calling timer.reset(), the timer will be paused, so you have to call timer.start() to start to time again.

Constructors and Methods

Constructors

cxxtimer::Timer(bool start = false)

If the parameter start is set to true, the timer will be started just after its construction. If set to false or ignored, the timer won't be automatically started after construction.

Besides the constructor above, the copy constructor

cxxtimer::Timer(const Timer& other)

and the move constructor

Timer(Timer&& other)

are defined.

start

Start/resume the timer.

void cxxtimer::start()

stop

void cxxtimer::stop()

Stop/pause the timer. After calling the method stop(), every call to count() will return the same value. To start timing again, you have to call start().

reset

void cxxtimer::reset()

Stop the timer and reset it. After calling the method reset(), every call to count() will return zero. To start timing again, you have to call start().

count

template <class duration_t = std::chrono::milliseconds>
typename duration_t::rep count() const

It returns the time elapsed so far. By default, it return the time in milliseconds. However, you can specify the precision you want. For example, to get the time in seconds, you can call count<std::chrono::seconds>(). The following options are available:

  • std::chrono::nanoseconds for nanoseconds.
  • std::chrono::microseconds for microseconds.
  • std::chrono::milliseconds for milliseconds (default).
  • std::chrono::seconds for seconds.
  • std::chrono::minutes for minutes.
  • std::chrono::hours for hours.

Linking

This is a header only library.

Requirements

The only build requirement is a C++ compiler that supports C++11, since cxxtimer.hpp library depends on C++ library chrono. For example GCC >= 5.0 or clang >= 3.4.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].