#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <sys/time.h>
#include "/dvr/debug/gcc4_debug.h"
int
main(int argc, char **argv)
{
int fd;
int cache_size;
char *buf;
off_t size_tmp;
off_t size;
struct stat fd_info;
struct timeval tpstart;
struct timeval tpend;
if(argc != 3)
ERRX(Argv error ! \n $bin file size_cache);
if((fd = open(argv[1], O_RDONLY)) < 0)
ERRX(open error);
if(-1 == lstat(argv[1], &fd_info))
ERRX(lstat error);
if((cache_size = atoi(argv[2])) < 0)
ERRX(cache_size error);
buf = (char *)malloc(cache_size);
if(NULL == buf)
ERRX(malloc error);
size = 0;
size_tmp = 0;
gettimeofday(&tpstart, NULL);
while(1)
{
if(0 == (size_tmp = read(fd, buf, cache_size)))
break;
size += size_tmp;
}
gettimeofday(&tpend, NULL);
free(buf);
close(fd);
// printf("size : %u; size : %u;\n", size, fd_info.st_size);
if(tpend.tv_usec < tpstart.tv_usec)
{
tpend.tv_usec += 1000000;
tpend.tv_sec -= 1;
}
printf("cahce_size:%10d \t time: \t %20ld \n", cache_size,
tpend.tv_usec - tpstart.tv_usec +
1000000 * (tpend.tv_sec - tpstart.tv_sec));
return 0;
}
|