mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
Microsecond granularity support
This commit is contained in:
parent
b75da563d9
commit
36a800f26c
13
lib/Timer.h
13
lib/Timer.h
@ -44,6 +44,7 @@ double usecond(void);
|
|||||||
typedef std::chrono::system_clock GridClock;
|
typedef std::chrono::system_clock GridClock;
|
||||||
typedef std::chrono::time_point<GridClock> GridTimePoint;
|
typedef std::chrono::time_point<GridClock> GridTimePoint;
|
||||||
typedef std::chrono::milliseconds GridTime;
|
typedef std::chrono::milliseconds GridTime;
|
||||||
|
typedef std::chrono::microseconds GridUsecs;
|
||||||
|
|
||||||
inline std::ostream& operator<< (std::ostream & stream, const std::chrono::milliseconds & time)
|
inline std::ostream& operator<< (std::ostream & stream, const std::chrono::milliseconds & time)
|
||||||
{
|
{
|
||||||
@ -55,7 +56,7 @@ class GridStopWatch {
|
|||||||
private:
|
private:
|
||||||
bool running;
|
bool running;
|
||||||
GridTimePoint start;
|
GridTimePoint start;
|
||||||
GridTime accumulator;
|
GridUsecs accumulator;
|
||||||
public:
|
public:
|
||||||
GridStopWatch () {
|
GridStopWatch () {
|
||||||
Reset();
|
Reset();
|
||||||
@ -67,17 +68,21 @@ public:
|
|||||||
}
|
}
|
||||||
void Stop(void) {
|
void Stop(void) {
|
||||||
assert(running == true);
|
assert(running == true);
|
||||||
accumulator+= std::chrono::duration_cast<GridTime>(GridClock::now()-start);
|
accumulator+= std::chrono::duration_cast<GridUsecs>(GridClock::now()-start);
|
||||||
running = false;
|
running = false;
|
||||||
};
|
};
|
||||||
void Reset(void){
|
void Reset(void){
|
||||||
running = false;
|
running = false;
|
||||||
start = GridClock::now();
|
start = GridClock::now();
|
||||||
accumulator = std::chrono::duration_cast<GridTime>(start-start);
|
accumulator = std::chrono::duration_cast<GridUsecs>(start-start);
|
||||||
}
|
}
|
||||||
GridTime Elapsed(void) {
|
GridTime Elapsed(void) {
|
||||||
assert(running == false);
|
assert(running == false);
|
||||||
return accumulator;
|
return std::chrono::duration_cast<GridTime>( accumulator );
|
||||||
|
}
|
||||||
|
uint64_t useconds(void){
|
||||||
|
assert(running == false);
|
||||||
|
return (uint64_t) accumulator.count();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user