#include <fcntl.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/dir.h>
#include <dirent.h>
#include <stdio.h>
static struct timeval start_time;
static struct timeval stop_time;
void start_timer(void)
{
// 시간을 start_time에 저장
gettimeofday(&start_time, 0);
}
void stop_timer(void)
{
// 시간을 stop_time에 저장
gettimeofday(&stop_time, 0);
}
unsigned long elapsed_sec(void)
{
return((stop_time.tv_sec-start_time.tv_sec)+(stop_time.tv_usec-start_time.tv_usec)/1000000);
}
unsigned long elapsed_msec(void)
{
return ((stop_time.tv_sec-start_time.tv_usec)*1000 + (stop_time.tv_usec-start_time.tv_usec)/1000);
}
void start_random(void)
{
struct timeval cur_time;
gettimeofday(&cur_time, 0);
srandom(cur_time.tv_usec);
}
unsigned long get_random(unsigned long range)
{
return (random() % range);
}
int main(int argc, char** argv, char** env)
{
int fd, idx, num;
char buf[1024];
long size;
fd = open("file.dat", O_RDONLY);
start_timer();
for(idx=0; idx<2000000;++idx)
{
read(fd, buf, 1024);
size += 1024;
}
stop_timer();
close(fd);
printf("Elapsed Time: %d secs\n", elapsed_sec());
printf("Total Read: %d Bytes\n", size);
printf("Average Read Speed: %d Bytes/sec\n",
size/elapsed_sec());
}