fixes for Power64
[tridge/junkcode.git] / rename_loop.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <sys/stat.h>
4 #include <sys/fcntl.h>
5
6 static struct timeval tp1,tp2;
7
8 void start_timer()
9 {
10         gettimeofday(&tp1,NULL);
11 }
12
13 double end_timer()
14 {
15         gettimeofday(&tp2,NULL);
16         return((tp2.tv_sec - tp1.tv_sec) + 
17                (tp2.tv_usec - tp1.tv_usec)*1.0e-6);
18 }
19
20 int main(void)
21 {
22         const char *name1 = "test1.dat";
23         const char *name2 = "test2.dat";
24         int fd, ops;
25
26         fd = open(name1, O_CREAT|O_RDWR|O_TRUNC, 0644);
27         if (fd == -1) {
28                 perror("open");
29                 exit(1);
30         }
31         close(fd);
32
33         start_timer();
34
35         ops = 0;
36
37         while (1) {
38                 if (rename(name1, name2) != 0 ||
39                     rename(name2, name1) != 0) {
40                         perror("rename");
41                         exit(1);
42                 }
43                 ops++;
44                 if (end_timer() >= 1.0) {
45                         printf("%.1f ops/sec\n", (2*ops) / end_timer());
46                         ops = 0;
47                         start_timer();
48                 }
49         }
50         
51         return 0;
52 }