1 
2 /*******************************************************************************
3  *  The BYTE UNIX Benchmarks - Release 3
4  *          Module: arith.c   SID: 3.3 5/15/91 19:30:19
5  *
6  *******************************************************************************
7  * Bug reports, patches, comments, suggestions should be sent to:
8  *
9  *	Ben Smith, Rick Grehan or Tom Yager
10  *	ben@bytepb.byte.com   rick_g@bytepb.byte.com   tyager@bytepb.byte.com
11  *
12  *******************************************************************************
13  *  Modification Log:
14  *  May 12, 1989 - modified empty loops to avoid nullifying by optimizing
15  *                 compilers
16  *  August 28, 1990 - changed timing relationship--now returns total number
17  *	                  of iterations (ty)
18  *  November 9, 1990 - made changes suggested by Keith Cantrell
19  *                        (digi!kcantrel) to defeat optimization
20  *                        to non-existence
21  *  October 22, 1997 - code cleanup to remove ANSI C compiler warnings
22  *                     Andy Kahn <kahn@zk3.dec.com>
23  *
24  ******************************************************************************/
25 
26 char SCCSid[] = "@(#) @(#)arith.c:3.3 -- 5/15/91 19:30:19";
27 /*
28  *  arithmetic test
29  *
30  */
31 
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include "timeit.c"
35 
36 int dumb_stuff(int);
37 
38 unsigned long iter;
39 
40 /* this function is called when the alarm expires */
report()41 void report()
42 {
43 	fprintf(stderr,"COUNT|%ld|1|lps\n", iter);
44 	exit(0);
45 }
46 
main(argc,argv)47 int main(argc, argv)
48 int	argc;
49 char	*argv[];
50 {
51 	int	duration;
52 	int result = 0;
53 
54 	if (argc != 2) {
55 		printf("Usage: %s duration\n", argv[0]);
56 		exit(1);
57 	}
58 
59 	duration = atoi(argv[1]);
60 
61 	/* set up alarm call */
62 	iter = 0;	/* init iteration count */
63 	wake_me(duration, report);
64 
65 	/* this loop will be interrupted by the alarm call */
66 	while (1)
67 	{
68         /* in switching to time-based (instead of iteration-based),
69            the following statement was added. It should not skew
70            the timings too much--there was an increment and test
71            in the "while" expression above. The only difference is
72            that now we're incrementing a long instead of an int.  (ty) */
73 	++iter;
74 	/* the loop calls a function to insure that something is done
75 	   the results of the function are fed back in (just so they
76 	   they won't be thrown away. A loop with
77 	   unused assignments may get optimized out of existence */
78 	result = dumb_stuff(result);
79 	}
80 }
81 
82 
83 /************************** dumb_stuff *******************/
dumb_stuff(i)84 int dumb_stuff(i)
85 int i;
86 {
87 #ifndef arithoh
88 	datum	x, y, z;
89 		z = 0;
90 #endif
91 		/*
92 		 *     101
93 		 * sum       i*i/(i*i-1)
94 		 *     i=2
95 		 */
96 		/* notice that the i value is always reset by the loop */
97 		for (i=2; i<=101; i++)
98 			{
99 #ifndef arithoh
100 			x = i;
101 			y = x*x;
102 			z += y/(y-1);
103 			}
104 return(x+y+z);
105 #else
106 }
107 return(0);
108 #endif
109 }
110 
111