mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-02-23 18:20:47 +08:00
Added Windows support to the BenchTimer.
This commit is contained in:
parent
7b0c4102fa
commit
5e3e6ff71a
@ -26,8 +26,14 @@
|
||||
#ifndef EIGEN_BENCH_TIMER_H
|
||||
#define EIGEN_BENCH_TIMER_H
|
||||
|
||||
#ifndef WIN32
|
||||
#include <sys/time.h>
|
||||
#include <unistd.h>
|
||||
#else
|
||||
#define NOMINMAX
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include <cstdlib>
|
||||
#include <numeric>
|
||||
|
||||
@ -40,7 +46,15 @@ class BenchTimer
|
||||
{
|
||||
public:
|
||||
|
||||
BenchTimer() { reset(); }
|
||||
BenchTimer()
|
||||
{
|
||||
#ifdef WIN32
|
||||
LARGE_INTEGER freq;
|
||||
QueryPerformanceFrequency(&freq);
|
||||
m_frequency = (double)freq.QuadPart;
|
||||
#endif
|
||||
reset();
|
||||
}
|
||||
|
||||
~BenchTimer() {}
|
||||
|
||||
@ -51,23 +65,35 @@ public:
|
||||
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)
|
||||
{
|
||||
return m_best;
|
||||
return m_best;
|
||||
}
|
||||
|
||||
#ifdef WIN32
|
||||
inline double getTime(void)
|
||||
#else
|
||||
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 timezone tz;
|
||||
gettimeofday(&tv, &tz);
|
||||
return (double)tv.tv_sec + 1.e-6 * (double)tv.tv_usec;
|
||||
#endif
|
||||
}
|
||||
|
||||
protected:
|
||||
|
||||
#ifdef WIN32
|
||||
double m_frequency;
|
||||
#endif
|
||||
double m_best, m_start;
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user