don't set page size by default
[tridge/junkcode.git] / snc.c
1 #include <fcntl.h>
2 #include <stdlib.h>
3 #include <sys/stat.h>
4 #include <sys/resource.h>
5
6 double walltime(void)
7 {
8         struct timeval tv;
9         gettimeofday(&tv, NULL);
10         return tv.tv_sec + 1.0e-6*tv.tv_usec;
11 }
12
13 main(int argc, char *argv[])
14 {
15         int fd;
16         int i;
17         char *buf;
18         int bufsize, sync, loops;
19         double t;
20
21         if (argc < 3) {
22                 printf("usage: %s <bufsize> <sync> <loops>\n", argv[0]);
23                 exit(1);
24         }
25
26         bufsize = atoi(argv[1]);
27         sync = atoi(argv[2]);
28         loops = atoi(argv[3]);
29
30         buf = (char *)malloc(bufsize);
31         if (!buf) exit(1);
32         memset(buf, 1, bufsize);
33
34         fd = open("sync.dat", O_CREAT|O_TRUNC|O_WRONLY | (sync?O_SYNC:0),0600);
35         t = walltime();
36
37         for (i=0;i<loops;i++) {
38                 write(fd, buf, bufsize);
39         }
40
41         t = walltime() - t;
42
43         printf("%g MB/sec\n", (1.0e-6*i*bufsize)/t);
44
45         unlink("sync.dat");
46 }