11 #ifndef EIGEN_BENCH_TIMERR_H 12 #define EIGEN_BENCH_TIMERR_H 14 #if defined(_WIN32) || defined(__CYGWIN__) 17 # define EIGEN_BT_UNDEF_NOMINMAX 19 # ifndef WIN32_LEAN_AND_MEAN 20 # define WIN32_LEAN_AND_MEAN 21 # define EIGEN_BT_UNDEF_WIN32_LEAN_AND_MEAN 24 #elif defined(__APPLE__) 25 #include <mach/mach_time.h> 30 static void escape(
void *p) {
31 asm volatile(
"" : :
"g"(p) :
"memory");
34 static void clobber() {
35 asm volatile(
"" : : :
"memory");
61 #if defined(_WIN32) || defined(__CYGWIN__) 63 QueryPerformanceFrequency(&freq);
64 m_frequency = (double)freq.QuadPart;
79 m_starts[CPU_TIMER] = getCpuTime();
80 m_starts[REAL_TIMER] = getRealTime();
84 m_times[CPU_TIMER] = getCpuTime() - m_starts[CPU_TIMER];
85 m_times[REAL_TIMER] = getRealTime() - m_starts[REAL_TIMER];
86 #if EIGEN_VERSION_AT_LEAST(2,90,0) 87 m_bests = m_bests.cwiseMin(m_times);
88 m_worsts = m_worsts.cwiseMax(m_times);
90 m_bests(0) = std::min(m_bests(0),m_times(0));
91 m_bests(1) = std::min(m_bests(1),m_times(1));
92 m_worsts(0) = std::max(m_worsts(0),m_times(0));
93 m_worsts(1) = std::max(m_worsts(1),m_times(1));
100 inline double value(
int TIMER = CPU_TIMER)
const 102 return m_times[TIMER];
107 inline double best(
int TIMER = CPU_TIMER)
const 109 return m_bests[TIMER];
114 inline double worst(
int TIMER = CPU_TIMER)
const 116 return m_worsts[TIMER];
121 inline double total(
int TIMER = CPU_TIMER)
const 123 return m_totals[TIMER];
126 inline double getCpuTime()
const 129 LARGE_INTEGER query_ticks;
130 QueryPerformanceCounter(&query_ticks);
131 return query_ticks.QuadPart/m_frequency;
133 return double(mach_absolute_time())*1e-9;
136 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
137 return double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec);
141 inline double getRealTime()
const 146 return (
double)st.wSecond + 1.e-3 * (double)st.wMilliseconds;
148 return double(mach_absolute_time())*1e-9;
151 clock_gettime(CLOCK_REALTIME, &ts);
152 return double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec);
157 #if defined(_WIN32) || defined(__CYGWIN__) 167 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
170 #define BENCH(TIMER,TRIES,REP,CODE) { \ 172 for(int uglyvarname1=0; uglyvarname1<TRIES; ++uglyvarname1){ \ 174 for(int uglyvarname2=0; uglyvarname2<REP; ++uglyvarname2){ \ 185 #ifdef EIGEN_BT_UNDEF_NOMINMAX 186 # undef EIGEN_BT_UNDEF_NOMINMAX 190 #ifdef EIGEN_BT_UNDEF_WIN32_LEAN_AND_MEAN 191 # undef EIGEN_BT_UNDEF_WIN32_LEAN_AND_MEAN 192 # undef WIN32_LEAN_AND_MEAN 195 #endif // EIGEN_BENCH_TIMERR_H double value(int TIMER=CPU_TIMER) const
Return the elapsed time in seconds between the last start/stop pair.
Definition: BenchTimer.h:100
Namespace containing all symbols from the Eigen library.
Definition: bench_norm.cpp:85
Elapsed time timer keeping the best try.
Definition: BenchTimer.h:55
double best(int TIMER=CPU_TIMER) const
Return the best elapsed time in seconds.
Definition: BenchTimer.h:107
double total(int TIMER=CPU_TIMER) const
Return the total elapsed time in seconds.
Definition: BenchTimer.h:121
double worst(int TIMER=CPU_TIMER) const
Return the worst elapsed time in seconds.
Definition: BenchTimer.h:114