19 #if __cplusplus >= 201103L || _MSC_VER >= 1600
21 #elif defined(__linux__)
22 # include <sys/time.h>
23 #elif defined(_MSC_VER) || defined(__MINGW32__)
24 # include <sys/timeb.h>
30 #if defined(__linux__)
31 # include <sys/resource.h>
39 inline std::ostream& formatTime(std::ostream& os,
double sec)
46 double ss = (flo % 60) + sec;
47 if (hh > 0) os << hh <<
"h ";
48 if (mm > 0) os << mm <<
"m ";
49 std::streamsize prec = os.precision();
71 template <
typename Clock>
80 void restart() { m_start = Clock::getTime(); }
83 double stop() {
return m_value = Clock::getTime() - m_start; }
86 double elapsed()
const {
return m_value; };
89 {
return formatTime(os, sw.m_value); }
91 #if __cplusplus >= 201103L || _MSC_VER >= 1600 // C++11 //
106 #if __cplusplus >= 201103L || _MSC_VER >= 1600 // C++11 //
108 struct CXX11WallClock
110 static double getTime()
112 return ((std::chrono::duration<double>)std::chrono::high_resolution_clock::now().time_since_epoch()).count();
117 typedef gsGenericStopwatch<CXX11WallClock>
gsStopwatch;
119 #elif defined(__linux__) // || defined(TARGET_OS_MAC) // LINUX //
122 struct LinuxWallClock
124 static double getTime()
125 { timeval
tv; gettimeofday(&tv, 0);
return tv.tv_sec + 1e-6*tv.tv_usec; }
129 typedef gsGenericStopwatch<LinuxWallClock>
gsStopwatch;
131 #elif defined(_MSC_VER) || defined(__MINGW32__) // WINDOWS //
133 struct WindowsWallClock
135 static double getTime()
143 return (
double)tb.time + tb.millitm / 1000.0;
148 typedef gsGenericStopwatch<WindowsWallClock>
gsStopwatch;
155 static double getTime()
156 { time_t secs; time (&secs);
return secs; }
169 #if defined(__linux__) // || defined(TARGET_OS_MAC) // LINUX //
176 static double getTime()
179 getrusage(RUSAGE_SELF, &ru);
180 return ru.ru_utime.tv_sec + 1.0e-6*ru.ru_utime.tv_usec;
194 static double getTime() {
return (
double) clock() / (double) CLOCKS_PER_SEC; }
double elapsed() const
Returns the last recorded elapsed time.
Definition: gsStopwatch.h:86
EIGEN_STRONG_INLINE tangent_expr< T > tv(const gsGeometryMap< T > &u)
The tangent boundary vector of a geometry map in 2D.
Definition: gsExpressions.h:4515
gsGenericStopwatch()
Declares a stop-watch.
Definition: gsStopwatch.h:77
void restart()
Start taking the time.
Definition: gsStopwatch.h:80
gsGenericStopwatch< WallClock > gsStopwatch
A stop-watch measuring real (wall) time.
Definition: gsStopwatch.h:160
double stop()
Return elapsed time in seconds.
Definition: gsStopwatch.h:83
A Stopwatch object can be used to measure execution time of code, algorithms, etc.
Definition: gsStopwatch.h:72
gsGenericStopwatch< CPUClock > gsCPUStopwatch
A stop-watch measuring CPU time.
Definition: gsStopwatch.h:198