
#ifndef __TIMER_H
#define __TIMER_H

#include <sys/time.h>
#include <time.h>

typedef struct {
	struct timeval tvBegin, tvEnd;
} duration_t;

static void timerBegin(duration_t *timer) {
	gettimeofday(&timer->tvBegin, 0);
}
static void timerEnd(duration_t *timer) {
	gettimeofday(&timer->tvEnd, 0);
}
static float timerAsFloat(duration_t *timer) {
	return ((timer->tvEnd.tv_usec - timer->tvBegin.tv_usec) / 1000000.0) + (timer->tvEnd.tv_sec - timer->tvBegin.tv_sec);
}

#endif
