#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)
{
int fd, idx;
long size;
char buf[1024];
long num;
fd = open("file.dat", O_CREAT | O_WRONLY | O_TRUNC, 0700);
size = 0;
start_timer();
for(idx=0;idx<2000000;++idx)
{
strncpy(buf, &idx, sizeof(int));
sprintf(buf+sizeof(int), "%d\0", idx);
sprintf(buf+sizeof(int)+20, "%d\0", idx);
write(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 Write Speed : %d bytes/secs\n", size/elapsed_sec());
}