#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#define MAXSIZE 6*1024*1024
/**
*计算两个时间的间隔,得到时间差
*@param struct timeval* resule 返回计算出来的时间
*@param struct timeval* x 需要计算的前一个时间
*@param struct timeval* y 需要计算的后一个时间
*return -1 failure ,0 success
**/
int timeval_subtract(struct timeval* result,struct timeval* x,struct timeval* y)
{
int nsec;
if(x->tv_sec>y->tv_sec)
return -1;
if((x->tv_sec==y->tv_sec)&&(x->tv_usec>y->tv_usec))
return -1;
result->tv_sec=(y->tv_sec-x->tv_sec);
result->tv_usec=(y->tv_usec-x->tv_usec);
if(result->tv_usec<0)
{
result->tv_sec--;
result->tv_usec+=1000000;
}
return 0;
}
int main(int argc ,char *argv[])
{
FILE *fp;
int readsize=0;
char readbuf[MAXSIZE];
struct timeval start,stop,diff;
LOOP:
if((fp=fopen("/mnt/usb/wanfeng.wav","r"))==NULL)
{
printf("file cannot open\n");
return -1;
}
gettimeofday(&start,0);
while(1)
{
if((readsize=fread(readbuf,1,MAXSIZE,fp)) <= 0)
{
break;
}
else
{
printf("read:%d\n",readsize);
}
}
gettimeofday(&stop,0);
timeval_subtract(&diff,&start,&stop);
printf("time start:%ld s:%ld us\n",start.tv_sec,start.tv_usec);
printf("time stop:%ld s:%ld us\n",stop.tv_sec,stop.tv_usec);
fclose(fp);
sleep(2);
goto LOOP;
}
usb读取速度测试
最新推荐文章于 2023-12-04 18:25:26 发布