New 'benchmarks' dir in test/, with first benchmark - unixbench-5.1.2, ported
[minix.git] / test / benchmarks / unixbench-5.1.2 / src / arith.c
blob37d436ec0d5ae1ad8369e75d6dd268493f96a83c
2 /*******************************************************************************
3 * The BYTE UNIX Benchmarks - Release 3
4 * Module: arith.c SID: 3.3 5/15/91 19:30:19
6 *******************************************************************************
7 * Bug reports, patches, comments, suggestions should be sent to:
9 * Ben Smith, Rick Grehan or Tom Yager
10 * ben@bytepb.byte.com rick_g@bytepb.byte.com tyager@bytepb.byte.com
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>
24 ******************************************************************************/
26 char SCCSid[] = "@(#) @(#)arith.c:3.3 -- 5/15/91 19:30:19";
28 * arithmetic test
32 #include <stdio.h>
33 #include <stdlib.h>
34 #include "timeit.c"
36 int dumb_stuff(int);
38 unsigned long iter;
40 /* this function is called when the alarm expires */
41 void report(int sig)
43 fprintf(stderr,"COUNT|%ld|1|lps\n", iter);
44 exit(0);
47 int main(int argc, char *argv[])
49 int duration;
50 int result = 0;
52 if (argc != 2) {
53 printf("Usage: %s duration\n", argv[0]);
54 exit(1);
57 duration = atoi(argv[1]);
59 /* set up alarm call */
60 iter = 0; /* init iteration count */
61 wake_me(duration, report);
63 /* this loop will be interrupted by the alarm call */
64 while (1)
66 /* in switching to time-based (instead of iteration-based),
67 the following statement was added. It should not skew
68 the timings too much--there was an increment and test
69 in the "while" expression above. The only difference is
70 that now we're incrementing a long instead of an int. (ty) */
71 ++iter;
72 /* the loop calls a function to insure that something is done
73 the results of the function are fed back in (just so they
74 they won't be thrown away. A loop with
75 unused assignments may get optimized out of existence */
76 result = dumb_stuff(result);
81 /************************** dumb_stuff *******************/
82 int dumb_stuff(i)
83 int i;
85 #ifndef arithoh
86 datum x, y, z;
87 z = 0;
88 #endif
90 * 101
91 * sum i*i/(i*i-1)
92 * i=2
94 /* notice that the i value is always reset by the loop */
95 for (i=2; i<=101; i++)
97 #ifndef arithoh
98 x = i;
99 y = x*x;
100 z += y/(y-1);
102 return(x+y+z);
103 #else
105 return(0);
106 #endif