mirror of
https://github.com/paboyle/Grid.git
synced 2025-04-09 21:50:45 +01:00
High res timer replaces getttimeofday
This commit is contained in:
parent
639aab6563
commit
9c21add0c6
@ -35,17 +35,8 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
|||||||
|
|
||||||
NAMESPACE_BEGIN(Grid)
|
NAMESPACE_BEGIN(Grid)
|
||||||
|
|
||||||
// Dress the output; use std::chrono
|
//typedef std::chrono::system_clock GridClock;
|
||||||
// C++11 time facilities better?
|
typedef std::chrono::high_resolution_clock GridClock;
|
||||||
inline double usecond(void) {
|
|
||||||
struct timeval tv;
|
|
||||||
tv.tv_sec = 0;
|
|
||||||
tv.tv_usec = 0;
|
|
||||||
gettimeofday(&tv,NULL);
|
|
||||||
return 1.0*tv.tv_usec + 1.0e6*tv.tv_sec;
|
|
||||||
}
|
|
||||||
|
|
||||||
typedef std::chrono::system_clock GridClock;
|
|
||||||
typedef std::chrono::time_point<GridClock> GridTimePoint;
|
typedef std::chrono::time_point<GridClock> GridTimePoint;
|
||||||
|
|
||||||
typedef std::chrono::seconds GridSecs;
|
typedef std::chrono::seconds GridSecs;
|
||||||
@ -53,6 +44,15 @@ typedef std::chrono::milliseconds GridMillisecs;
|
|||||||
typedef std::chrono::microseconds GridUsecs;
|
typedef std::chrono::microseconds GridUsecs;
|
||||||
typedef std::chrono::microseconds GridTime;
|
typedef std::chrono::microseconds GridTime;
|
||||||
|
|
||||||
|
extern GridTimePoint theProgramStart;
|
||||||
|
// Dress the output; use std::chrono
|
||||||
|
// C++11 time facilities better?
|
||||||
|
inline double usecond(void) {
|
||||||
|
auto usecs = std::chrono::duration_cast<GridUsecs>(GridClock::now()-theProgramStart);
|
||||||
|
return 1.0*usecs.count();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
inline std::ostream& operator<< (std::ostream & stream, const GridSecs & time)
|
inline std::ostream& operator<< (std::ostream & stream, const GridSecs & time)
|
||||||
{
|
{
|
||||||
stream << time.count()<<" s";
|
stream << time.count()<<" s";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user