-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCELLTimestamp.hpp
49 lines (36 loc) · 1.28 KB
/
CELLTimestamp.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#ifndef _CELLTimestamp_HPP_
#define _CELLTimestamp_HPP_
#include <chrono>
#include <functional>
#define NOWTIME_SEC std::chrono::duration_cast<std::chrono::seconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
#define NOWTIME_MILLI std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
#define NOWTIME_MICRO std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
#define NOWTIME_NANO std::chrono::duration_cast<std::chrono::nanoseconds>(std::chrono::high_resolution_clock::now().time_since_epoch()).count();
class CELLTimestamp
{
public:
CELLTimestamp()
{
this->update();
}
~CELLTimestamp()
{
}
void update(){_begin = std::chrono::high_resolution_clock::now();}
double getElapsedTimeInSec()
{
return this->getElapsedTimeInMircoSec() * 0.000001;
}
double getElapsedTimeInMilliSec()
{
return this->getElapsedTimeInMircoSec() * 0.001;
}
long long getElapsedTimeInMircoSec()
{
return std::chrono::duration_cast<std::chrono::microseconds>(std::chrono::high_resolution_clock::now() - _begin).count();
}
protected:
std::chrono::time_point < std::chrono::high_resolution_clock> _begin;
};
#endif