16
void usage __P((void));
23
struct timeval start_time, end_time;
25
int bytes, ch, cnt, fd, ops;
26
char *fname, buf[100 * 1024];
31
while ((ch = getopt(argc, argv, "b:f:o:")) != EOF)
34
if ((bytes = atoi(optarg)) > sizeof(buf)) {
36
"max -b option %d\n", sizeof(buf));
44
if ((ops = atoi(optarg)) <= 0) {
45
fprintf(stderr, "illegal -o option value\n");
57
if ((fd = open(fname, O_RDWR | O_CREAT, 0666)) == -1) {
62
memset(buf, 0, bytes);
64
printf("running: %d ops\n", ops);
66
(void)gettimeofday(&start_time, NULL);
67
for (cnt = 0; cnt < ops; ++cnt) {
68
if (write(fd, buf, bytes) != bytes) {
69
fprintf(stderr, "write: %s\n", strerror(errno));
72
if (lseek(fd, (off_t)0, SEEK_SET) == -1) {
73
fprintf(stderr, "lseek: %s\n", strerror(errno));
77
fprintf(stderr, "fsync: %s\n", strerror(errno));
81
(void)gettimeofday(&end_time, NULL);
83
if (end_time.tv_sec != start_time.tv_sec) {
84
end_time.tv_usec += 1000000;
87
usecs = (end_time.tv_sec - start_time.tv_sec) * 1000000 +
88
end_time.tv_usec - start_time.tv_usec;
89
printf("Elapsed time: %ld.%06ld seconds\n",
90
usecs / 1000000, usecs % 1000000);
91
printf("%d ops: %7.2f ops per second\n",
92
ops, (float)1000000 * ops/usecs);
101
(void)fprintf(stderr,
102
"usage: testfile [-b bytes] [-f file] [-o ops]\n");