From b19e637a829ef6cb59fab1944bc119ae12349512 Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Fri, 12 Mar 2021 23:27:48 +0100 Subject: [PATCH] fixup test. --- hacks/direct_disk_speed_test.cc | 74 +++++++++++++++++++++++++++++---- 1 file changed, 65 insertions(+), 9 deletions(-) diff --git a/hacks/direct_disk_speed_test.cc b/hacks/direct_disk_speed_test.cc index c4e5b69f7..0e20e2fdd 100644 --- a/hacks/direct_disk_speed_test.cc +++ b/hacks/direct_disk_speed_test.cc @@ -1,8 +1,52 @@ #include #include #include +#include +#include +#include -int test(int block_size, int blocks, int gap, int rdisk) +int test_posix(int block_size, int blocks, int gap, int rdisk, int nocache) +{ + struct timeval start; + gettimeofday(&start, NULL); + + int f = -1; + if (rdisk) { + f = open("/dev/rdisk3", O_RDWR); + } else { + f = open("/dev/disk3", O_RDWR); + } + if (f == -1) { + printf("open failed.\n"); + return -1; + } + + fcntl(f, F_NOCACHE, nocache); + + void* buffer = malloc(block_size); + if (!buffer) { + printf("malloc failed.\n"); + return -1; + } + + for (int i = 0; i < blocks; ++i) { + write(f, buffer, block_size); + if (gap > 0) { + lseek(f, gap, SEEK_CUR); + } + } + + close(f); + + struct timeval end; + gettimeofday(&end, NULL); + float duration = ((end.tv_sec + end.tv_usec / 1e6) - (start.tv_sec + start.tv_usec / 1e6)); + printf("POSIX: block_size=%d blocks=%d gap=%d rdisk=%d nocache=%d time=%f\n", block_size, blocks, gap, rdisk, nocache, duration); + return 0; +} + + +int test_stdio(int block_size, int blocks, int gap, int rdisk) { struct timeval start; gettimeofday(&start, NULL); @@ -38,7 +82,7 @@ int test(int block_size, int blocks, int gap, int rdisk) struct timeval end; gettimeofday(&end, NULL); float duration = ((end.tv_sec + end.tv_usec / 1e6) - (start.tv_sec + start.tv_usec / 1e6)); - printf("block_size=%d blocks=%d gap=%d rdisk=%d time=%f\n", block_size, blocks, gap, rdisk, duration); + printf("STDIO: block_size=%d blocks=%d gap=%d rdisk=%d time=%f\n", block_size, blocks, gap, rdisk, duration); return 0; } @@ -46,13 +90,25 @@ int test(int block_size, int blocks, int gap, int rdisk) int main() { for (int i = 0; i < 2; i++) { - test(4096, 4096, 0, i); - test(4096, 4096, 0, i); - test(8192, 2048, 0, i); - test(4096, 4096, 4096, i); - test(4096, 4096, 65536, i); - test(8192, 2048, 65536, i); - test(16384, 1024, 65536, i); +/* + test_posix(4096, 4096, 0, i); + test_posix(4096, 4096, 0, i); + test_posix(8192, 2048, 0, i); + test_posix(4096, 4096, 4096, i); + test_posix(4096, 4096, 65536, i); + test_posix(8192, 2048, 65536, i); + test_posix(16384, 1024, 65536, i); +*/ + for (int j = 0; j < 2; j++) { + // test_posix(4096, 262144, 0, i, j); + // test_posix(8192, 131072, 0, i, j); + // test_posix(16384, 65536, 0, i, j); + test_posix(32768, 32768, 0, i, j); + test_posix(65536, 16384, 0, i, j); + test_posix(131072, 8192, 0, i, j); + test_posix(262144, 4096, 0, i, j); + test_posix(524288, 2048, 0, i, j); + } } } -- 2.30.2