summaryrefslogtreecommitdiffstatshomepage
path: root/3rdparty/unittest-cpp/UnitTest++/Posix/TimeHelpers.cpp
blob: 65c63937a0e7892ef37939639b23018ba12d970a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "TimeHelpers.h"
#include <unistd.h>

namespace UnitTest {

Timer::Timer()
{
    m_startTime.tv_sec = 0;
    m_startTime.tv_usec = 0;
}

void Timer::Start()
{
    gettimeofday(&m_startTime, 0);
}

double Timer::GetTimeInMs() const
{
    struct timeval currentTime;
    gettimeofday(&currentTime, 0);

	double const dsecs = currentTime.tv_sec - m_startTime.tv_sec;
    double const dus = currentTime.tv_usec - m_startTime.tv_usec;

	return (dsecs * 1000.0) + (dus / 1000.0);
}

void TimeHelpers::SleepMs(int ms)
{
    usleep(ms * 1000);
}

}