forked from mpusz/mp-units
examples, alternative namespaces : Part2 of put alternative namespace definitions in local headers.
examples, clcpp_response,alternative_namespaces::clcpp_response : use fmt functions for showing precision of quantities examples, alternative namespaces : combined the alternative namespace quantity typedefs in header files. examples, alternative namespaces : add simple timer example
This commit is contained in:
committed by
Mateusz Pusz
parent
c886590b03
commit
6b7e5893d2
@@ -0,0 +1,35 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "./timer.h"
|
||||
|
||||
/*
|
||||
simple timer, useful for perf timing etc
|
||||
*/
|
||||
|
||||
using namespace units::experimental;
|
||||
using namespace units::si::literals;
|
||||
|
||||
int main()
|
||||
{
|
||||
std::cout << "Simple timer using mpusz/units ...\n";
|
||||
|
||||
auto const period = 0.5q_s;
|
||||
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';
|
||||
}
|
||||
Reference in New Issue
Block a user