Annotation of Net2/tests/benchmarks/randread.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Random I/O benchmark.
                      3:  *
                      4:  * Process reads blocks from a
                      5:  * file in a random order. 
                      6:  */
                      7: #include <sys/types.h>
                      8: #include <sys/file.h>
                      9: #include <sys/stat.h>
                     10: 
                     11: char   *malloc();
                     12: 
                     13: main(argc, argv)
                     14:        char *argv[];
                     15: {
                     16:        char *buf;
                     17:        int size, fd, bn, maxblocks;
                     18:        struct stat sb;
                     19:        register int i, niter;
                     20: 
                     21:        if (argc < 3) {
                     22:                printf("usage: %s file read-size #reads\n", argv[0]);
                     23:                exit(1);
                     24:        }
                     25:        fd = open(argv[1], O_RDONLY);
                     26:        if (fd < 0) {
                     27:                perror(argv[1]);
                     28:                exit(2);
                     29:        }
                     30:        fstat(fd, &sb);
                     31:        buf = malloc(sb.st_blksize);
                     32:        if (buf == (char *)0) {
                     33:                printf("Couldn't allocate i/o buffer.\n");
                     34:                exit(3);
                     35:        }
                     36:        size = atoi(argv[2]);
                     37:        if (size > sb.st_blksize) {
                     38:                printf("Reads must be no larger than block size (%d)\n",
                     39:                    sb.st_blksize);
                     40:                exit(4);
                     41:        }
                     42:        niter = atoi(argv[3]);
                     43:        printf("%d random %d byte reads, file size %d kb (bsize %d)\n",
                     44:            niter, size, sb.st_size / 1024, sb.st_blksize);
                     45:        for (i = 0; i < niter; i++) {
                     46:                lseek(fd, random() % sb.st_size, L_SET);
                     47:                read(fd, buf, size);
                     48:        }
                     49: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.