本例以40ms为周期调用接口
#include <iostream>
#include <chrono>
#include <thread>
#include <functional>
uint64_t systemTimeUS()
{
using namespace std::chrono;
time_point<system_clock, microseconds> nowus = time_point_cast<microseconds>(system_clock::now());
return static_cast<uint64_t>(nowus.time_since_epoch().count());
}
uint64_t systemTimeMS()
{
using namespace std::chrono;
time_point<system_clock, milliseconds> nowus = time_point_cast<milliseconds>(system_clock::now());
return static_cast<uint64_t>(nowus.time_since_epoch().count());
}
void doAction()
{
printf("[work] time: [%lu]ms\n", systemTimeMS());
std::this_thread::sleep_for(std::chrono::milliseconds(7));
}
void doAction_20ms()
{
printf("[work] time: [%lu]ms\n", systemTimeMS())