added -W
[tridge/junkcode.git] / readloop.c
1 #include <unistd.h>
2 #include <fcntl.h>
3 #include <sys/time.h>
4
5 struct timeval tp1,tp2;
6
7 static void start_timer()
8 {
9   gettimeofday(&tp1,NULL);
10 }
11
12 static double end_timer()
13 {
14   gettimeofday(&tp2,NULL);
15   return((tp2.tv_sec - tp1.tv_sec) + 
16          (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
17 }
18
19
20 char buf[1024*1024];
21
22 int main(int argc, char *argv[])
23 {
24         char *fname = argv[1];
25         int fd;
26         int count=0;
27
28         fd = open(fname,O_RDONLY);
29
30         while (1) {
31                 int ret;
32
33                 if (count == 0) {
34                         start_timer();
35                 }
36                 
37                 ret = read(fd, buf, sizeof(buf));
38
39                 lseek(fd, 0, SEEK_SET);
40
41                 if (count++ == 10) {
42                         printf("%g MB/sec\n", count*ret/(1.0e6*end_timer()));
43                         count=0;
44                 }
45         }
46
47         return 0;
48 }