?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download

  1. #include "TimeHelpers.h"
  2. #include <unistd.h>
  3.  
  4. namespace UnitTest {
  5.  
  6.    Timer::Timer()
  7.    {
  8.       m_startTime.tv_sec = 0;
  9.       m_startTime.tv_usec = 0;
  10.    }
  11.  
  12.    void Timer::Start()
  13.    {
  14.       gettimeofday(&m_startTime, 0);
  15.    }
  16.  
  17.    double Timer::GetTimeInMs() const
  18.    {
  19.       struct timeval currentTime;
  20.       gettimeofday(&currentTime, 0);
  21.  
  22.       double const dsecs = currentTime.tv_sec - m_startTime.tv_sec;
  23.       double const dus = currentTime.tv_usec - m_startTime.tv_usec;
  24.  
  25.       return (dsecs * 1000.0) + (dus / 1000.0);
  26.    }
  27.  
  28.    void TimeHelpers::SleepMs(int ms)
  29.    {
  30.       usleep(static_cast<useconds_t>(ms * 1000));
  31.    }
  32.  
  33. }
  34.