#include "timer.h"

timer::timer()
{
  timeusec = 0;
  cpuusec = 0;
}

timer::~timer()
{
}

void timer::reset()
{
  timeusec = 0;
  cpuusec = 0;
}

void timer::start()
{
  getrusage( RUSAGE_SELF, &ustart );
  gettimeofday(&rstart, NULL);
}

void timer::stop()
{
  getrusage( RUSAGE_SELF, &ustop );
  gettimeofday(&rstop, NULL);
  timeusec = timeusec +
    ((double)rstop.tv_sec+( ((double)rstop.tv_usec)/1000000.0 )) -
    ((double)rstart.tv_sec+( ((double)rstart.tv_usec)/1000000.0 ) );
  cpuusec = cpuusec +
    ((double)ustop.ru_utime.tv_sec+( ((double)ustop.ru_utime.tv_usec)/1000000.0) )-
    ((double)ustart.ru_utime.tv_sec+( ((double)ustart.ru_utime.tv_usec)/1000000.0) );
}

double timer::getseconds()
{
  return timeusec;
}

double timer::getcpu()
{
  return cpuusec;
}
