8 int test_posix(int block_size, int blocks, int gap, int rdisk, int nocache)
11 gettimeofday(&start, NULL);
15 f = open("/dev/rdisk3", O_RDWR);
17 f = open("/dev/disk3", O_RDWR);
20 printf("open failed.\n");
24 fcntl(f, F_NOCACHE, nocache);
26 void* buffer = malloc(block_size);
28 printf("malloc failed.\n");
32 for (int i = 0; i < blocks; ++i) {
33 write(f, buffer, block_size);
35 lseek(f, gap, SEEK_CUR);
42 gettimeofday(&end, NULL);
43 float duration = ((end.tv_sec + end.tv_usec / 1e6) - (start.tv_sec + start.tv_usec / 1e6));
44 printf("POSIX: block_size=%d blocks=%d gap=%d rdisk=%d nocache=%d time=%f\n", block_size, blocks, gap, rdisk, nocache, duration);
49 int test_stdio(int block_size, int blocks, int gap, int rdisk)
52 gettimeofday(&start, NULL);
56 f = fopen("/dev/rdisk3", "r+b");
58 f = fopen("/dev/disk3", "r+b");
61 printf("fopen failed.\n");
67 void* buffer = malloc(block_size);
69 printf("malloc failed.\n");
73 for (int i = 0; i < blocks; ++i) {
74 fwrite(buffer, block_size, 1, f);
76 fseek(f, gap, SEEK_CUR);
83 gettimeofday(&end, NULL);
84 float duration = ((end.tv_sec + end.tv_usec / 1e6) - (start.tv_sec + start.tv_usec / 1e6));
85 printf("STDIO: block_size=%d blocks=%d gap=%d rdisk=%d time=%f\n", block_size, blocks, gap, rdisk, duration);
92 for (int i = 0; i < 2; i++) {
94 test_posix(4096, 4096, 0, i);
95 test_posix(4096, 4096, 0, i);
96 test_posix(8192, 2048, 0, i);
97 test_posix(4096, 4096, 4096, i);
98 test_posix(4096, 4096, 65536, i);
99 test_posix(8192, 2048, 65536, i);
100 test_posix(16384, 1024, 65536, i);
102 for (int j = 0; j < 2; j++) {
103 // test_posix(4096, 262144, 0, i, j);
104 // test_posix(8192, 131072, 0, i, j);
105 // test_posix(16384, 65536, 0, i, j);
106 test_posix(32768, 32768, 0, i, j);
107 test_posix(65536, 16384, 0, i, j);
108 test_posix(131072, 8192, 0, i, j);
109 test_posix(262144, 4096, 0, i, j);
110 test_posix(524288, 2048, 0, i, j);