4 * Tests reading 1 byte at a time from a file.
6 * $DragonFly: src/test/sysperf/read1.c,v 1.1 2004/08/13 02:28:42 dillon Exp $
11 #include <sys/resource.h>
12 #include <sys/fcntl.h>
17 main(int ac, char **av)
28 fprintf(stderr, "%s filesize[k,m]\n", av[0]);
31 bytes = strtol(av[1], &ptr, 0);
32 if (*ptr == 'k' || *ptr == 'K') {
34 } else if (*ptr == 'm' || *ptr == 'M') {
37 fprintf(stderr, "Illegal numerical suffix: %s\n", ptr);
41 fprintf(stderr, "I can't handle %d sized buffers\n", bytes);
45 filename = "read1.dat";
46 fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
49 filename = "/tmp/read1.dat";
50 fd = open(filename, O_RDWR|O_CREAT|O_TRUNC, 0666);
57 for (i = 0; i < bytes; i += sizeof(Buf)) {
58 int n = (bytes - i > sizeof(Buf)) ? sizeof(Buf) : bytes - i;
59 if (write(fd, Buf, n) != n) {
75 while (stop_timing(0, NULL) == 0) {
76 for (j = 0; j < 256 * 1024; ++j) {
77 if (read(fd, &c, 1) != 1)
84 for (j = 0; j < i; ++j) {
85 if (read(fd, &c, 1) != 1)
88 stop_timing(j, "read 1char from file:");