Annotation of Net2/tests/benchmarks/bench-4.1/randrewrite.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * Random I/O benchmark.
                      3:  *
                      4:  * Process writes blocks to a file in a
                      5:  * random order.  Writes are constrained
                      6:  * to overwrite existing blocks.  This
                      7:  * test should be run after the seqio test
                      8:  * so that a file is constructed.
                      9:  */
                     10: #include <sys/types.h>
                     11: #include <sys/file.h>
                     12: #include <sys/stat.h>
                     13: 
                     14: char   *malloc();
                     15: 
                     16: main(argc, argv)
                     17:        char *argv[];
                     18: {
                     19:        char *buf;
                     20:        int fd, bn, nblocks;
                     21:        struct stat sb;
                     22:        register int i, niter;
                     23: 
                     24:        if (argc < 3) {
                     25:                printf("usage: %s file #writes\n", argv[0]);
                     26:                exit(1);
                     27:        }
                     28:        fd = open(argv[1], 1);
                     29:        if (fd < 0) {
                     30:                perror(argv[1]);
                     31:                exit(2);
                     32:        }
                     33:        fstat(fd, &sb);
                     34:        buf = malloc(1024);
                     35:        if (buf == (char *)0) {
                     36:                printf("Couldn't allocate i/o buffer.\n");
                     37:                exit(3);
                     38:        }
                     39:        nblocks = sb.st_size / 1024;
                     40:        niter = atoi(argv[2]);
                     41:        printf("%d random writes in %d block file (block size %d)\n", 
                     42:            niter, nblocks, 1024);
                     43:        for (i = 0; i < niter; i++) {
                     44:                bn = random() % nblocks;
                     45:                lseek(fd, bn * 1024, 0);
                     46:                write(fd, buf, 1024);
                     47:        }
                     48: }

unix.superglobalmegacorp.com

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