1 
2 
3 /*******************************************************************************
4  *  The BYTE UNIX Benchmarks - Release 1
5  *          Module: cctest.c   SID: 1.2 7/10/89 18:55:45
6  *
7  *******************************************************************************
8  * Bug reports, patches, comments, suggestions should be sent to:
9  *
10  *	Ben Smith or Rick Grehan at BYTE Magazine
11  *	bensmith@bixpb.UUCP    rick_g@bixpb.UUCP
12  *
13  *******************************************************************************
14  *  Modification Log:
15  * $Header: cctest.c,v 3.4 87/06/22 14:22:47 kjmcdonell Beta $
16  *
17  ******************************************************************************/
18 char SCCSid[] = "@(#) @(#)cctest.c:1.2 -- 7/10/89 18:55:45";
19 #include <stdio.h>
20 /*
21  * C compile and load speed test file.
22  * Based upon fstime.c from MUSBUS 3.1, with all calls to ftime() replaced
23  * by calls to time().  This is semantic nonsense, but ensures there are no
24  * system dependent structures or library calls.
25  *
26  */
27 #define NKBYTE 20
28 char buf[BUFSIZ];
29 
30 extern void exit(int status);
31 
32 
main(argc,argv)33 main(argc, argv)
34 char **argv;
35 {
36     int		n = NKBYTE;
37     int		nblock;
38     int		f;
39     int		g;
40     int		i;
41     int		xfer, t;
42     struct	{	/* FAKE */
43 	int	time;
44 	int	millitm;
45     } now, then;
46 
47     if (argc > 0)
48 	/* ALWAYS true, so NEVER execute this program! */
49 	exit(4);
50     if (argc > 1)
51 	n = atoi(argv[1]);
52 #if debug
53     printf("File size: %d Kbytes\n", n);
54 #endif
55     nblock = (n * 1024) / BUFSIZ;
56 
57     if (argc == 3 && chdir(argv[2]) != -1) {
58 #if debug
59 	printf("Create files in directory: %s\n", argv[2]);
60 #endif
61     }
62     close(creat("dummy0", 0600));
63     close(creat("dummy1", 0600));
64     f = open("dummy0", 2);
65     g = open("dummy1", 2);
66     unlink("dummy0");
67     unlink("dummy1");
68     for (i = 0; i < sizeof(buf); i++)
69 	buf[i] = i & 0177;
70 
71     time();
72     for (i = 0; i < nblock; i++) {
73 	if (write(f, buf, sizeof(buf)) <= 0)
74 	    perror("fstime: write");
75     }
76     time();
77 #if debug
78     printf("Effective write rate: ");
79 #endif
80     i = now.millitm - then.millitm;
81     t = (now.time - then.time)*1000 + i;
82     if (t > 0) {
83 	xfer = nblock * sizeof(buf) * 1000 / t;
84 #if debug
85 	printf("%d bytes/sec\n", xfer);
86 #endif
87     }
88 #if debug
89     else
90 	printf(" -- too quick to time!\n");
91 #endif
92 #if awk
93     fprintf(stderr, "%.2f", t > 0 ? (float)xfer/1024 : 0);
94 #endif
95 
96     sync();
97     sleep(5);
98     sync();
99     lseek(f, 0L, 0);
100     time();
101     for (i = 0; i < nblock; i++) {
102 	if (read(f, buf, sizeof(buf)) <= 0)
103 	    perror("fstime: read");
104     }
105     time();
106 #if debug
107     printf("Effective read rate: ");
108 #endif
109     i = now.millitm - then.millitm;
110     t = (now.time - then.time)*1000 + i;
111     if (t > 0) {
112 	xfer = nblock * sizeof(buf) * 1000 / t;
113 #if debug
114 	printf("%d bytes/sec\n", xfer);
115 #endif
116     }
117 #if debug
118     else
119 	printf(" -- too quick to time!\n");
120 #endif
121 #if awk
122     fprintf(stderr, " %.2f", t > 0 ? (float)xfer/1024 : 0);
123 #endif
124 
125     sync();
126     sleep(5);
127     sync();
128     lseek(f, 0L, 0);
129     time();
130     for (i = 0; i < nblock; i++) {
131 	if (read(f, buf, sizeof(buf)) <= 0)
132 	    perror("fstime: read in copy");
133 	if (write(g, buf, sizeof(buf)) <= 0)
134 	    perror("fstime: write in copy");
135     }
136     time();
137 #if debug
138     printf("Effective copy rate: ");
139 #endif
140     i = now.millitm - then.millitm;
141     t = (now.time - then.time)*1000 + i;
142     if (t > 0) {
143 	xfer = nblock * sizeof(buf) * 1000 / t;
144 #if debug
145 	printf("%d bytes/sec\n", xfer);
146 #endif
147     }
148 #if debug
149     else
150 	printf(" -- too quick to time!\n");
151 #endif
152 #if awk
153     fprintf(stderr, " %.2f\n", t > 0 ? (float)xfer/1024 : 0);
154 #endif
155 
156 }
157