home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / byte-benchmarks3.1 / part01 / src / arith.c next >
Encoding:
C/C++ Source or Header  |  1992-02-01  |  2.6 KB  |  106 lines

  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.  *
  22.  ******************************************************************************/
  23.  
  24. char SCCSid[] = "@(#) @(#)arith.c:3.3 -- 5/15/91 19:30:19";
  25. /*
  26.  *  arithmetic test
  27.  *
  28.  */
  29.  
  30. #include <stdio.h>
  31. #include "timeit.c"
  32.  
  33. unsigned long iter;
  34.  
  35. /* this function is called when the alarm expires */
  36. report()
  37. {
  38.     fprintf(stderr,"%ld loops\n", iter);
  39.     exit(0);
  40. }
  41.  
  42. main(argc, argv)
  43. int    argc;
  44. char    *argv[];
  45. {
  46.     int    duration;
  47.     int result = 0;
  48.  
  49.     if (argc != 2) {
  50.         printf("Usage: %s duration\n", argv[0]);
  51.         exit(1);
  52.     }
  53.  
  54.     duration = atoi(argv[1]);
  55.  
  56.     /* set up alarm call */
  57.     iter = 0;    /* init iteration count */
  58.     wake_me(duration, report);
  59.  
  60.     /* this loop will be interrupted by the alarm call */
  61.     while (1)
  62.     {
  63.         /* in switching to time-based (instead of iteration-based),
  64.            the following statement was added. It should not skew
  65.            the timings too much--there was an increment and test
  66.            in the "while" expression above. The only difference is 
  67.            that now we're incrementing a long instead of an int.  (ty) */
  68.     ++iter;
  69.     /* the loop calls a function to insure that something is done 
  70.        the results of the function are fed back in (just so they 
  71.        they won't be thrown away. A loop with 
  72.        unused assignments may get optimized out of existence */
  73.     result = dumb_stuff(result);
  74.     }
  75. }
  76.  
  77.  
  78. /************************** dumb_stuff *******************/
  79. dumb_stuff(i)
  80. int i;
  81. {
  82. #ifndef arithoh
  83.     datum    x, y, z;
  84.         z = 0;
  85. #endif
  86.         /*
  87.          *     101
  88.          * sum       i*i/(i*i-1)
  89.          *     i=2
  90.          */
  91.         /* notice that the i value is always reset by the loop */
  92.         for (i=2; i<=101; i++) 
  93.             {
  94. #ifndef arithoh
  95.             x = i;
  96.             y = x*x;
  97.             z += y/(y-1);
  98.             }
  99. return(x+y+z);
  100. #else
  101.             }
  102. return(0);
  103. #endif
  104. }
  105.  
  106.