/*
This is timer.h, a small header file dedicated to timing the execution
of C code.
Copyright 2010 LORIA (CNRS, INPL, INRIA, UHP, U-Nancy 2).
It has been written by S. Chevillard.
This file is free software: you can redistribute it and/or modify
it under the terms of the GNU Lesser General Public License as
published by the Free Software Foundation, either version 3 of the
License, or (at your option) any later version.
This file is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public License
along with liberferfc. If not, see .
*/
#ifndef H_TIMER
#define H_TIMER
#include
/* Basic timing functions. A timer is a variable t of type timer_t. */
/* timer_init(t) initializes it with 0. */
/* timer_start(t) begins counting time. */
/* timer_stop(t) stops counting time. */
/* It is possible to perform several start/stop with the same timer. */
/* In this case, the total time is accumulated. */
/* timer_get(t) returns the number of µs counted by t, as a double. */
typedef struct {
struct timeval begin;
struct timeval end;
time_t seconds;
suseconds_t microseconds;
} timer_type;
#define timer_init(t) \
do { \
(t).seconds=0; \
(t).microseconds=0; \
} while(0)
#define timer_start(t) gettimeofday(&((t).begin), NULL)
#define timer_stop(t) \
do { \
gettimeofday(&((t).end), NULL); \
(t).seconds += (t).end.tv_sec - (t).begin.tv_sec; \
(t).microseconds += (t).end.tv_usec - (t).begin.tv_usec; \
} while(0)
#define timer_get(t) (((double)((t).seconds))*1000000. + (double)((t).microseconds))
#endif /* H_TIMER */