23 return m_n_cycle > 0 ? m_time_acc / m_n_cycle : .0;
35 if(m_state == STOP)
return;
56 os << header <<
" " << setw(25) << left << m_name << right
58 <<
" * " << setw( 8) << m_n_cycle
59 <<
" = " << setw( 8) << (int)round(m_time_acc/1000) <<
" s" << endl;
66 usleep(1000 * time_msec);
68 os <<
"PHTimer2::test(): " << m_time_acc <<
" for " << time_msec << endl;
74 if (m_state == RUN)
return -1;
76 long diff_sec = m_time_stop.tv_sec - m_time_start.tv_sec;
77 long diff_nsec = m_time_stop.tv_nsec - m_time_start.tv_nsec;
79 return 1000 * diff_sec + 1e-6 * diff_nsec;
84 return clock_gettime(CLOCK_MONOTONIC_RAW, tp);
void print_stat(std::string header=" Timer2:", std::ostream &os=std::cout) const
PHTimer2(const std::string &name="Generic Timer")
double elapsed() const
In millisecond.
void test(unsigned int time_msec, std::ostream &os=std::cout)
Test this class by waiting for a given time (in ms).
double get_time_per_cycle() const
int get_clock_time(timespec *tp)