Linux计算时间间隔

Linux计算时间间隔:
 
#include
#include

/*
int gettimeofday(struct timeval *tv, struct timezone *tz);
int settimeofday(const struct timeval *tv , const struct timezone *tz);
strut timeval {
long tv_sec; /* 秒数 */
long tv_usec; /* 微秒数 */
};
*/

struct timeval start,end;
int timeuse;

void time()
{
gettimeofday( &end, NULL );
timeuse = 1000000 * ( end.tv_sec – start.tv_sec ) + end.tv_usec – start.tv_usec;
timeuse /= 1000000;
printf(“time used: %ds\n”, timeuse);
}