Annotation of Net2/tests/benchmarks/bench-4.1/randwrite.c, revision 1.1

1.1     ! root        1: /*
        !             2:  * Random I/O benchmark.
        !             3:  *
        !             4:  * Process writes blocks to 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 < 4) {
        !            22:                printf("usage: %s file max-file-size #writes\n", argv[0]);
        !            23:                exit(1);
        !            24:        }
        !            25:        fd = creat(argv[1], 0644);
        !            26:        if (fd < 0) {
        !            27:                perror(argv[1]);
        !            28:                exit(2);
        !            29:        }
        !            30:        buf = malloc(1024);
        !            31:        if (buf == (char *)0) {
        !            32:                printf("Couldn't allocate i/o buffer.\n");
        !            33:                exit(3);
        !            34:        }
        !            35:        /* file size is in megabytes */
        !            36:        fstat(fd, &sb);
        !            37:        maxblocks = atoi(argv[2]) * ((1024 * 1024) / 1024);
        !            38:        niter = atoi(argv[3]);
        !            39:        printf("%d random writes (block size %d)\n", niter, 1024);
        !            40:        for (i = 0; i < niter; i++) {
        !            41:                bn = random() % maxblocks;
        !            42:                lseek(fd, bn * 1024, 0);
        !            43:                write(fd, buf, 1024);
        !            44:        }
        !            45: }

unix.superglobalmegacorp.com

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