00001 #ifndef TEMP_TOOLS_H_
00002 #define TEMP_TOOLS_H_
00003
00004 #include <time.h>
00005 #include <sys/time.h>
00006
00007 struct timeval;
00008 typedef struct timeval tiempo_t;
00009
00010 inline long dif_sec_tmp( tiempo_t *begin, tiempo_t *end )
00011 {
00012 long diffs;
00013
00014 diffs = end->tv_sec - begin->tv_sec;
00015
00016 if ( ( end->tv_usec - begin->tv_usec ) < -500000 )
00017 diffs--;
00018 else
00019 if ( ( end->tv_usec - begin->tv_usec ) > 500000 )
00020 diffs++;
00021
00022 return( diffs );
00023 }
00024
00025 inline long dif_msec_tmp(tiempo_t *p_tmp_ini, tiempo_t *p_tmp_fin)
00026 {
00027 long sec,usec;
00028 long rtn;
00029
00030 if ((p_tmp_ini == NULL) || (p_tmp_fin == NULL))
00031 {
00032 return 0;
00033 }
00034
00035 sec = (p_tmp_fin->tv_sec - p_tmp_ini->tv_sec) * 1000;
00036 usec = p_tmp_fin->tv_usec - p_tmp_ini->tv_usec;
00037 rtn = sec + usec/1000;
00038 return rtn;
00039 }
00040
00041 inline long dif_usec_tmp(tiempo_t *tmp_ini, tiempo_t *tmp_end)
00042 {
00043 long usec_ini, usec_end, usec_diff;
00044
00045 if ((tmp_ini == NULL) || (tmp_end == NULL))
00046 {
00047 return 0;
00048 }
00049
00050 usec_ini = (tmp_ini->tv_sec)*1000000 + tmp_ini->tv_usec;
00051 usec_end = (tmp_end->tv_sec)*1000000 + tmp_end->tv_usec;
00052 usec_diff = usec_end - usec_ini;
00053
00054 return usec_diff;
00055 }
00056
00057
00058 #endif // TEMP_TOOLS_H_