2015-07-23 17:31:13 +01:00
|
|
|
#ifndef GRID_TIME_H
|
|
|
|
#define GRID_TIME_H
|
2015-07-27 10:32:28 +01:00
|
|
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
#include <ctime>
|
|
|
|
#include <chrono>
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
namespace Grid {
|
2015-07-27 10:32:28 +01:00
|
|
|
|
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
// Dress the output; use std::chrono
|
2015-07-27 10:32:28 +01:00
|
|
|
|
|
|
|
// C++11 time facilities better?
|
|
|
|
double usecond(void);
|
2015-07-23 17:31:13 +01:00
|
|
|
|
|
|
|
typedef std::chrono::system_clock GridClock;
|
|
|
|
typedef std::chrono::time_point<GridClock> GridTimePoint;
|
|
|
|
typedef std::chrono::milliseconds GridTime;
|
|
|
|
|
2015-12-28 16:38:31 +00:00
|
|
|
inline std::ostream& operator<< (std::ostream & stream, const std::chrono::milliseconds & time)
|
|
|
|
{
|
|
|
|
stream << time.count()<<" ms";
|
|
|
|
return stream;
|
|
|
|
}
|
2015-07-23 17:31:13 +01:00
|
|
|
|
|
|
|
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
|