I ran a simple file I/O performance test. I wrote 1GB data to a file and measure the time elapsed. The result shows the write time takes only about 0.45sec and performance is over 17Gbps. I know this is impossible but I can't find anything wrong in my test code. Below is my test routine. I can see correct file in d:\a.bin.
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
char *ioBuf;
int i, io_buf_size = 1024 * 1024;
unsigned int io_amt = 0;
FILE *fp;
clock_t start, end;
double elapsed;
ioBuf = (char *)malloc(1024 * 1024 * sizeof(char));
for (i = 0; i < io_buf_size; i++) {
ioBuf[i] = i % 255;
}
if ((fp = fopen("d:\\a.bin", "wb")) == NULL) {
printf("open file fail, err \n");
return 1;
}
start = clock();
for (i = 0; i < 1024; i++) {
io_amt += fwrite(ioBuf, sizeof(char), io_buf_size, fp);
if (fflush(fp) != 0) printf("flushing buffer failed!\n");
}
end = clock();
elapsed = (double)(end - start) / CLOCKS_PER_SEC;
printf("fwrtie %dGB takes : %f sec\n", io_amt / (1024 * 1024 * 1024), elapsed);
fclose(fp);
free(ioBuf);
return 0;
}