Eigen::BenchTimer Class Reference

#include <BenchTimer.h>

Public Member Functions

 BenchTimer ()
 
 ~BenchTimer ()
 
void reset ()
 
void start ()
 
void stop ()
 
double value (int TIMER=CPU_TIMER) const
 
double best (int TIMER=CPU_TIMER) const
 
double worst (int TIMER=CPU_TIMER) const
 
double total (int TIMER=CPU_TIMER) const
 
double getCpuTime () const
 
double getRealTime () const
 

Protected Attributes

Vector2d m_starts
 
Vector2d m_times
 
Vector2d m_bests
 
Vector2d m_worsts
 
Vector2d m_totals
 

Detailed Description

Elapsed time timer keeping the best try.

On POSIX platforms we use clock_gettime with CLOCK_PROCESS_CPUTIME_ID. On Windows we use QueryPerformanceCounter

Important: on linux, you must link with -lrt

Constructor & Destructor Documentation

◆ BenchTimer()

Eigen::BenchTimer::BenchTimer ( )
inline
57  {
58 #if defined(_WIN32) || defined(__CYGWIN__)
59  LARGE_INTEGER freq;
60  QueryPerformanceFrequency(&freq);
61  m_frequency = (double)freq.QuadPart;
62 #endif
63  reset();
64  }
void reset()
Definition: BenchTimer.h:68

References reset().

◆ ~BenchTimer()

Eigen::BenchTimer::~BenchTimer ( )
inline
66 {}

Member Function Documentation

◆ best()

double Eigen::BenchTimer::best ( int  TIMER = CPU_TIMER) const
inline

Return the best elapsed time in seconds

98 { return m_bests[TIMER]; }
Vector2d m_bests
Definition: BenchTimer.h:142

References m_bests.

Referenced by __attribute__(), bench(), and main().

◆ getCpuTime()

double Eigen::BenchTimer::getCpuTime ( ) const
inline
108  {
109 #ifdef _WIN32
110  LARGE_INTEGER query_ticks;
111  QueryPerformanceCounter(&query_ticks);
112  return query_ticks.QuadPart / m_frequency;
113 #elif __APPLE__
114  return double(mach_absolute_time()) * 1e-9;
115 #else
116  timespec ts;
117  clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ts);
118  return double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec);
119 #endif
120  }
Array< double, 1, 3 > e(1./3., 0.5, 2.)

References e().

Referenced by start(), and stop().

◆ getRealTime()

double Eigen::BenchTimer::getRealTime ( ) const
inline
122  {
123 #ifdef _WIN32
124  SYSTEMTIME st;
125  GetSystemTime(&st);
126  return (double)st.wSecond + 1.e-3 * (double)st.wMilliseconds;
127 #elif __APPLE__
128  return double(mach_absolute_time()) * 1e-9;
129 #else
130  timespec ts;
131  clock_gettime(CLOCK_REALTIME, &ts);
132  return double(ts.tv_sec) + 1e-9 * double(ts.tv_nsec);
133 #endif
134  }

References e().

Referenced by start(), and stop().

◆ reset()

void Eigen::BenchTimer::reset ( )
inline
68  {
69  m_bests.fill(1e9);
70  m_worsts.fill(0);
71  m_totals.setZero();
72  }
Vector2d m_totals
Definition: BenchTimer.h:144
Vector2d m_worsts
Definition: BenchTimer.h:143

References m_bests, m_totals, and m_worsts.

Referenced by __attribute__(), bench_svd(), and BenchTimer().

◆ start()

void Eigen::BenchTimer::start ( )
inline
73  {
76  }
double getCpuTime() const
Definition: BenchTimer.h:108
Vector2d m_starts
Definition: BenchTimer.h:140
double getRealTime() const
Definition: BenchTimer.h:122
@ REAL_TIMER
Definition: BenchTimer.h:46
@ CPU_TIMER
Definition: BenchTimer.h:46

References Eigen::CPU_TIMER, getCpuTime(), getRealTime(), m_starts, and Eigen::REAL_TIMER.

Referenced by __attribute__(), bench_svd(), and main().

◆ stop()

void Eigen::BenchTimer::stop ( )
inline
77  {
80 #if EIGEN_VERSION_AT_LEAST(2, 90, 0)
81  m_bests = m_bests.cwiseMin(m_times);
82  m_worsts = m_worsts.cwiseMax(m_times);
83 #else
84  m_bests(0) = std::min(m_bests(0), m_times(0));
85  m_bests(1) = std::min(m_bests(1), m_times(1));
86  m_worsts(0) = std::max(m_worsts(0), m_times(0));
87  m_worsts(1) = std::max(m_worsts(1), m_times(1));
88 #endif
89  m_totals += m_times;
90  }
Vector2d m_times
Definition: BenchTimer.h:141
#define min(a, b)
Definition: datatypes.h:22
#define max(a, b)
Definition: datatypes.h:23

References Eigen::CPU_TIMER, getCpuTime(), getRealTime(), m_bests, m_starts, m_times, m_totals, m_worsts, max, min, and Eigen::REAL_TIMER.

Referenced by __attribute__(), bench_svd(), and main().

◆ total()

double Eigen::BenchTimer::total ( int  TIMER = CPU_TIMER) const
inline

Return the total elapsed time in seconds.

106 { return m_totals[TIMER]; }

References m_totals.

Referenced by main().

◆ value()

double Eigen::BenchTimer::value ( int  TIMER = CPU_TIMER) const
inline

Return the elapsed time in seconds between the last start/stop pair

94 { return m_times[TIMER]; }

References m_times.

Referenced by __attribute__(), bench_svd(), and main().

◆ worst()

double Eigen::BenchTimer::worst ( int  TIMER = CPU_TIMER) const
inline

Return the worst elapsed time in seconds

102 { return m_worsts[TIMER]; }

References m_worsts.

Member Data Documentation

◆ m_bests

Vector2d Eigen::BenchTimer::m_bests
protected

Referenced by best(), reset(), and stop().

◆ m_starts

Vector2d Eigen::BenchTimer::m_starts
protected

Referenced by start(), and stop().

◆ m_times

Vector2d Eigen::BenchTimer::m_times
protected

Referenced by stop(), and value().

◆ m_totals

Vector2d Eigen::BenchTimer::m_totals
protected

Referenced by reset(), stop(), and total().

◆ m_worsts

Vector2d Eigen::BenchTimer::m_worsts
protected

Referenced by reset(), stop(), and worst().


The documentation for this class was generated from the following file: