#include <sys/types.h>
#include <sys/time.h>
long ast_tvdiff_ms(struct timeval end, struct timeval start)
{
/* the offset by 1,000,000 below is intentional...
it avoids differences in the way that division
is handled for positive and negative numbers, by ensuring
that the divisor is always positive
*/
long sec_dif = (long)(end.tv_sec - start.tv_sec) * 1000;
long usec_dif = (1000000 + end.tv_usec - start.tv_usec) / 1000 - 1000;
return sec_dif + usec_dif;
}
struct timeval ast_tvnow(void)
{
struct timeval t;
gettimeofday(&t, NULL);
return t;
}
int main(int argc,char** argv)
{
struct timeval start = ast_tvnow() ;
printf("ms=%d", ast_tvdiff_ms(ast_tvnow(),start));
}