#include "Timer.h"
#include <sys/time.h>
#include <stdio.h>

static long get_usec()
{
    struct timeval tv;
    gettimeofday(&tv, NULL);
    return tv.tv_sec * 1000000 + tv.tv_usec;
}

Timer::Timer()
{
    m_start_time = 0;
    m_elapsed = 0;
    start();
}

void Timer::start()
{
    m_start_time = get_usec();
}

void Timer::stop()
{
    m_elapsed = get_usec() - m_start_time;
}

void Timer::print()
{
    printf("Elapsed: %ldus\n", m_elapsed);
}
