This is header-only library that provide std::chrono based timer. No external dependencies.
Features:
-
Initialization
Use default rep (double) and period (std::ratio<1>, which means seconds)
flow::timer timer;
Specify rep and period
flow::timer<int, std::milli> timer;
-
Get elapsed duration of code fragment
flow::timer timer; // Some work here auto dur = timer.duration();
-
Get elapsed duration and return result of any callable object
// unpack std::pair auto [elapsed, result] = flow::timer<>::duration_r( // any callable object (like function or lambda), // callable object arguments... );
-
Get elapsed time of code fragment
flow::timer timer; // Some work here auto elapsed_time = timer.elapsed();
-
Get elapsed time of any callable object
// unpack std::pair auto [elapsed, result] = flow::timer<>::elapsed_r( // any callable object (like function or lambda), // callable object arguments... );
-
Get elapsed time and return result of any callable object
// unpack std::pair auto [elapsed, result] = flow::timer<>::elapsed_r( // any callable object (like function or lambda), // callable object arguments... );
-
Get average execution time
auto avg = flow::timer<>::avg( // count of iterations, // any callable object (like function or lambda), // callable object arguments... );
-
Get average execution duration
auto avg_dur = flow::timer<>::avg_duration( // count of iterations, // any callable object (like function or lambda), // callable object arguments... );
-
Reset the timer
flow::timer timer; // Some work here timer.reset();
-
Get the moment, when the timer was started (or was reset)
timer.started_in();
Put the flow
directory in your project and include flow/timer.hpp
. Nothing to build.
C++17