and this my code, image is test record
Code: Select all
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define BLOCK_SIZE 4096 // 4KB
int main() {
FILE* fp;
char* buf;
long long i, j, n;
double t1, t2, speed;
char const* _FileName = "test.dat";
n = (10 * 1024 * 1024 ) / (4);
buf = (char*)malloc(BLOCK_SIZE);
printf("Test start\n");
printf("Create data ...\n");
srand(time(NULL));
for (i = 0; i < BLOCK_SIZE; i++) {
buf[i] = rand() % 256;
}
printf("Create data done\n");
printf("\n");
printf("Write file ...\n");
fp = fopen(_FileName, "wb");
t1 = clock();
for (i = 0; i < n; i++) {
fwrite(buf, BLOCK_SIZE, 1, fp);
}
t2 = clock();
fclose(fp);
printf("Write file done\n");
double ttt = n * BLOCK_SIZE / (t2 - t1);
speed = n * BLOCK_SIZE / ((t2 - t1) / CLOCKS_PER_SEC);
printf("Write speed: %.2f MB/s\n", speed / 1024 / 1024);
printf("\n");
printf("Read file ...\n");
fp = fopen(_FileName, "rb");
t1 = clock();
for (i = 0; i < n; i++) {
fread(buf, BLOCK_SIZE, 1, fp);
}
t2 = clock();
fclose(fp);
printf("Read file done\n");
speed = n * BLOCK_SIZE / ((t2 - t1) / CLOCKS_PER_SEC);
printf("Read speed: %.2f MB/s\n", speed / 1024 / 1024);
free(buf);
return 0;
}