Added Windows support to the BenchTimer.

This commit is contained in:
Hauke Heibel 2009-10-20 22:08:13 +02:00
parent 7b0c4102fa
commit 5e3e6ff71a

View File

@ -26,8 +26,14 @@
#ifndef EIGEN_BENCH_TIMER_H #ifndef EIGEN_BENCH_TIMER_H
#define EIGEN_BENCH_TIMER_H #define EIGEN_BENCH_TIMER_H
#ifndef WIN32
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#else
#define NOMINMAX
#include <windows.h>
#endif
#include <cstdlib> #include <cstdlib>
#include <numeric> #include <numeric>
@ -40,7 +46,15 @@ class BenchTimer
{ {
public: public:
BenchTimer() { reset(); } BenchTimer()
{
#ifdef WIN32
LARGE_INTEGER freq;
QueryPerformanceFrequency(&freq);
m_frequency = (double)freq.QuadPart;
#endif
reset();
}
~BenchTimer() {} ~BenchTimer() {}
@ -51,23 +65,35 @@ public:
m_best = std::min(m_best, getTime() - m_start); m_best = std::min(m_best, getTime() - m_start);
} }
/** Return the best elapsed time. /** Return the best elapsed time in seconds.
*/ */
inline double value(void) inline double value(void)
{ {
return m_best; return m_best;
} }
#ifdef WIN32
inline double getTime(void)
#else
static inline double getTime(void) static inline double getTime(void)
#endif
{ {
#ifdef WIN32
LARGE_INTEGER query_ticks;
QueryPerformanceCounter(&query_ticks);
return query_ticks.QuadPart/m_frequency;
#else
struct timeval tv; struct timeval tv;
struct timezone tz; struct timezone tz;
gettimeofday(&tv, &tz); gettimeofday(&tv, &tz);
return (double)tv.tv_sec + 1.e-6 * (double)tv.tv_usec; return (double)tv.tv_sec + 1.e-6 * (double)tv.tv_usec;
#endif
} }
protected: protected:
#ifdef WIN32
double m_frequency;
#endif
double m_best, m_start; double m_best, m_start;
}; };