2019-04-01 22:03:32 +02:00
|
|
|
#include <AK/Assertions.h>
|
2019-05-18 02:00:01 +02:00
|
|
|
#include <AK/Time.h>
|
2019-05-28 11:53:16 +02:00
|
|
|
#include <LibCore/CElapsedTimer.h>
|
2019-03-27 01:31:53 +01:00
|
|
|
#include <sys/time.h>
|
2019-03-25 01:42:15 +01:00
|
|
|
|
2019-04-10 16:14:44 +02:00
|
|
|
void CElapsedTimer::start()
|
2019-03-25 01:42:15 +01:00
|
|
|
{
|
2019-04-01 22:03:32 +02:00
|
|
|
m_valid = true;
|
2019-03-25 01:42:15 +01:00
|
|
|
gettimeofday(&m_start_time, nullptr);
|
|
|
|
}
|
|
|
|
|
2019-04-10 16:14:44 +02:00
|
|
|
int CElapsedTimer::elapsed() const
|
2019-03-25 01:42:15 +01:00
|
|
|
{
|
2019-04-01 22:03:32 +02:00
|
|
|
ASSERT(is_valid());
|
2019-03-25 01:42:15 +01:00
|
|
|
struct timeval now;
|
|
|
|
gettimeofday(&now, nullptr);
|
|
|
|
struct timeval diff;
|
2019-06-06 18:02:28 +02:00
|
|
|
timeval_sub(now, m_start_time, diff);
|
2019-03-25 01:42:15 +01:00
|
|
|
return diff.tv_sec * 1000 + diff.tv_usec / 1000;
|
|
|
|
}
|