linux 用时统计
用于记录便于使用时复制
#include
#include
static void tv_sub(struct timeval *out, struct timeval *in)
{
if ( (out->tv_usec -= in->tv_usec) < 0){
--out->tv_sec;
out->tv_usec += 1000000;
}
out->tv_sec -= in->tv_sec;
}
int main()
{
struct timeval out,in;
gettimeofday(&in,NULL);
sleep(1);
gettimeofday(&out,NULL);
tv_sub(&out,&in);
printf("用时:%d.%d\n",out.tv_sec,out.tv_usec);
return 0;
}
showtooltip