mirror of
https://github.com/paboyle/Grid.git
synced 2025-12-20 04:34:29 +00:00
Committing incomplete work for parameter file I/O.
MacroMagic.h is central. Guido and I plan to move over to generating virtual (XML, JSON, YAML, text, binary) encoding from macro based system.
This commit is contained in:
52
lib/Timer.h
Normal file
52
lib/Timer.h
Normal file
@@ -0,0 +1,52 @@
|
||||
#ifndef GRID_TIME_H
|
||||
#define GRID_TIME_H
|
||||
|
||||
#include <sys/time.h>
|
||||
#include <ctime>
|
||||
#include <chrono>
|
||||
|
||||
namespace Grid {
|
||||
|
||||
|
||||
// Dress the output; use std::chrono
|
||||
|
||||
// C++11 time facilities better?
|
||||
double usecond(void);
|
||||
|
||||
typedef std::chrono::system_clock GridClock;
|
||||
typedef std::chrono::time_point<GridClock> GridTimePoint;
|
||||
typedef std::chrono::milliseconds GridTime;
|
||||
|
||||
|
||||
class GridStopWatch {
|
||||
private:
|
||||
bool running;
|
||||
GridTimePoint start;
|
||||
GridTime accumulator;
|
||||
public:
|
||||
GridStopWatch () {
|
||||
Reset();
|
||||
}
|
||||
void Start(void) {
|
||||
assert(running == false);
|
||||
start = GridClock::now();
|
||||
running = true;
|
||||
}
|
||||
void Stop(void) {
|
||||
assert(running == true);
|
||||
accumulator+= std::chrono::duration_cast<GridTime>(GridClock::now()-start);
|
||||
running = false;
|
||||
};
|
||||
void Reset(void){
|
||||
running = false;
|
||||
start = GridClock::now();
|
||||
accumulator = std::chrono::duration_cast<GridTime>(start-start);
|
||||
}
|
||||
GridTime Elapsed(void) {
|
||||
assert(running == false);
|
||||
return accumulator;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user