#ifndef _CELLTimestamp_hpp_
#define _CELLTimestamp_hpp_
//为了避免同一个头文件被包含(include)多次,C/C++中有两种宏实现方式:
//一种是#ifndef方式;另一种是#pragma once方式。
#pragma once
// 达到微秒的计时器
#include<chrono>
using namespace std::chrono;
class CELLTimestamp{
public:
CELLTimestamp()
{
update();
}
~CELLTimestamp(){
}
void update(){
_begin = high_resolution_clock::now();
}
//获取当前秒
double getElapsedSecond(){
return getElapsedTimeInMicroSec()*0.000001;
}
//获取毫秒
long long getElapsedTimeInMilliSec(){
return this->getElapsedTimeInMicroSec()*0.001;
}
//获取微秒
long long getElapsedTimeInMicroSec(){
return duration_cast<microseconds>(high_resolution_clock::now() - _begin).count();
}
protected:
// 高精度计时器
time_point<high_resolution_clock> _begin;
};
#endif