Annotation of Net2/tests/benchmarks/randbread.c, revision 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 fd, bn, maxblocks;
        !            18:        struct stat sb;
        !            19:        register int i, niter;
        !            20: 
        !            21:        if (argc < 3) {
        !            22:                printf("usage: %s file #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:        buf = malloc(sb.st_blksize);
        !            31:        if (buf == (char *)0) {
        !            32:                printf("Couldn't allocate i/o buffer.\n");
        !            33:                exit(3);
        !            34:        }
        !            35:        fstat(fd, &sb);
        !            36:        niter = atoi(argv[2]);
        !            37:        printf("%d random block reads, file size %d kb (bsize %d)\n",
        !            38:            niter, sb.st_size / 1024, sb.st_blksize);
        !            39:        for (i = 0; i < niter; i++) {
        !            40:                bn = (random() % sb.st_size) / sb.st_size;
        !            41:                lseek(fd, bn * sb.st_blksize, L_SET);
        !            42:                read(fd, buf, sb.st_blksize);
        !            43:        }
        !            44: }

unix.superglobalmegacorp.com

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