I want to know the difference between
char *text = (char *)malloc(4096);
memset(text, 'a', 4096);
int fd = open(filepath, O_RDWR | O_CREAT | O_DIRECT);
for(int i=0; i<1000; i++) {
write(fd, (void *)text, 4096);
fsync(fd);
}
close (fd);
and
char *text = (char *)malloc(4096);
memset(text, 'a', 4096);
int fd = open(filepath, O_RDWR | O_CREAT | O_DIRECT | O_SYNC); //<----Difference
for(int i=0; i<1000; i++) {
write(fd, (void *)text, 4096);
// fsync(fd); <--------------------------------------------------Difference
}
close (fd);
The performance of the code above is way slower than that below.