2020-03-19 11:43:12 +00:00
|
|
|
|
2020-12-28 15:18:02 +01:00
|
|
|
#include <units/quantity_io.h>
|
2020-03-19 11:43:12 +00:00
|
|
|
#include <iostream>
|
|
|
|
#include "./timer.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
simple timer, useful for perf timing etc
|
|
|
|
*/
|
|
|
|
|
|
|
|
using namespace units::experimental;
|
2021-03-16 12:03:25 +01:00
|
|
|
using namespace units::isq::si::literals;
|
2020-03-19 11:43:12 +00:00
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
std::cout << "Simple timer using mpusz/units ...\n";
|
|
|
|
|
2020-09-09 19:20:35 +02:00
|
|
|
auto const period = 0.5_q_s;
|
2020-03-19 11:43:12 +00:00
|
|
|
auto const duration = 10 * period;
|
|
|
|
|
|
|
|
timer t;
|
|
|
|
|
|
|
|
auto const start_time = t();
|
|
|
|
|
|
|
|
std::cout << "Started at " << start_time <<'\n';
|
|
|
|
|
|
|
|
auto prev = start_time;
|
|
|
|
for (auto now = t(); (now - start_time) < duration; now = t() ) {
|
|
|
|
if ( (now - prev ) >= period ){
|
|
|
|
prev = now;
|
|
|
|
std::cout << "tick (" << now << ")\n";;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
t.stop();
|
|
|
|
|
|
|
|
std::cout << "finished at " << t() << '\n';
|
|
|
|
}
|