/*
   server/timer.cc
   This file is part of the Osirion project and is distributed under 
   the terms and conditions of the GNU General Public License version 2 
*/

#include "timer.h"

#include <unistd.h>
#include <iostream>

namespace server {

Timer::Timer()
{
	gettimeofday(&this->timer_tick, &this->timer_tz);
 	this->timer_elapsed = 0;
}

Timer::~Timer()
{
}

void Timer::mark()
{
	gettimeofday(&timer_tick, &timer_tz);
}

float Timer::elapsed()
{	
	struct timeval tick;
	struct timezone tick_tz;
	
	gettimeofday(&tick, &tick_tz);
	
	// calculate elapsed time in 10^-6 seconds
	long delta =  (tick.tv_sec - timer_tick.tv_sec) * 1000000 + (tick.tv_usec - timer_tick.tv_usec);
	return( (float) delta / 1000000.0f);
}

}