home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / C / CLMFEB85.ZIP / BENMRK.LTG < prev    next >
Encoding:
Text File  |  1988-07-25  |  5.0 KB  |  265 lines

  1.  
  2.  
  3.                        The Deref Benchmark
  4.                         C Compiler Review
  5.                  February 1985 COMPUTER LANGUAGE
  6.  
  7.  
  8. /*
  9. **     deref.c -- benchmark program to examine the effeciency
  10. **  of pointer dereferencing
  11. */
  12.  
  13. #define LOOPS    50000      /* how many loops */
  14. #define BELL     7          /* ASCII bell character */
  15.  
  16. struct cptr1  {
  17.         char ********************ptr1;
  18.         };
  19.         
  20. main()
  21. {
  22. unsigned i;
  23. char yekdorb;
  24. struct cptr1 ********************pointer;
  25.  
  26.         printf("%u loops\n", LOOPS);
  27.         
  28.         for (i = 0; i <= LOOPS; i++)
  29.             yekdorb = ********************
  30.                 (********************pointer).ptr1;
  31.                         
  32.         printf("%cfinished\n", BELL);
  33.         exit(0);
  34. }
  35.  
  36.  
  37.  
  38.  
  39.                         The Fib Benchmark
  40.                        C Compiler Analysis
  41.                  February 1985 COMPUTER LANGUAGE
  42.  
  43.  
  44. /* Fibonacci Number Generator in C */
  45. #include "STDIO.H"
  46. #define NTIMES 10         /* number of times to computer Fibonacci value */
  47.  
  48. #define NUMBER 24         /* biggest that can be computed in 16 bits */
  49.  
  50.  
  51. void main()                /* compute Fibonacci value */
  52.     {
  53.     int i;
  54.     unsigned value, fib();
  55.  
  56.     printf("%d iterations:  ", NTIMES);
  57.     for (i = 1;  i <= NTIMES;  i++)
  58.         value = fib(NUMBER);
  59.     printf("Fibonacci(%d) = %u.\n", NUMBER, value);
  60.     exit(0);
  61.     }
  62.  
  63. unsigned fib(x)            /* compute Fibonacci number recursively */
  64. int x;
  65.     {
  66.  
  67.     if (x > 2)
  68.         return (fib(x - 1) + fib(x - 2));
  69.     else return (1);
  70.     }
  71.  
  72.  
  73.  
  74.  
  75.  
  76.                       The Matrix Benchmark
  77.                        C Compiler Analysis
  78.                  February 1985 COMPUTER LANGUAGE
  79.  
  80. /*
  81. ** Matrix.c -- a benchmark based on the matrix multiplication
  82. ** program given by Jerry Pournelle in Byte October 1982 p. 254.
  83. **
  84. ** Type conversions have been made explicit with casts. Array
  85. ** and loop indices now start at 0.
  86. */
  87.  
  88. #define M     20
  89. #define N     20
  90. #define BELL  7
  91.  
  92. char gup;
  93. double summ, a[M][N], b[N][M], c[M][M];
  94.  
  95. main()
  96. {
  97.  
  98.     summ = 0.0;
  99.     printf("Hit any character to start\n");
  100.     gup = getchar();
  101.     
  102.     filla();
  103.     printf("\nA filled\n");
  104.     fillb();
  105.     printf("\nB filled\n");
  106.     fillc();
  107.     printf("\nC filled\n");
  108.     
  109.     matmult();
  110.     printf("\nMultiplied\n");
  111.     summit();
  112.     
  113.     printf("The sum is: %20f\n", summ);
  114.     putchar(BELL);
  115. }
  116.  
  117. filla()
  118. {
  119. int i, j;
  120.  
  121.     for (i=0; i < M; i++)
  122.         for (j = 0; j < N; j++)
  123.             a[i][j] = (double) (i+1) + (j+1);
  124. }
  125.  
  126. fillb()
  127. {
  128. int i, j;
  129.  
  130.     for (i=0; i < N; i++)
  131. è        for (j = 0; j < M; j++)
  132.             b[i][j] = (double) (int) (((i+1) + (j+1)) / (j+1));
  133. }
  134.  
  135. fillc()
  136. {
  137. int i, j;
  138.  
  139.     for (i=0; i < M; i++)
  140.         for (j = 0; j < M; j++)
  141.             c[i][j] = (double) 0;
  142. }
  143.  
  144. matmult()
  145. {
  146. int i, j, k;
  147.  
  148.     for (i = 0; i < M; i++)
  149.         for (j = 0; j < N; j++)
  150.             for (k = 0; k < M; k++)
  151.                 c[i][j] = c[i][j] + a[i][k]*b[k][j];
  152. }
  153.  
  154. summit()
  155. {
  156. int i, j;
  157.  
  158.     for (i = 0; i < M; i++)
  159.         for (j = 0; j < M; j++)
  160.             summ = summ + c[i][j];
  161. }
  162.  
  163.  
  164.  
  165.  
  166.                  Sieve of Eratosthenes Benchmark
  167.                        C Compiler Analysis
  168.                  February 1985 COMPUTER LANGUAGE
  169.  
  170.  
  171. /* Eratosthenes Sieve Prime Number Program in C */
  172. #define TRUE    1
  173. #define FALSE    0
  174. #define SIZE    8190
  175.  
  176. char flags[SIZE+1];
  177.  
  178. main()
  179. {
  180. int i, prime, k, count, iter;
  181.  
  182.     printf("10 iterations.\n");
  183.     for (iter = 1; iter <= 10; iter++) {
  184.         count = 0;
  185.         for (i = 0; i <= SIZE; i++)
  186.             flags[i] = TRUE;
  187.         for (i = 0; i<= SIZE; i++) {
  188.             if (flags[i]) {
  189.                 prime = i + i + 3;
  190.                 for (k = i + prime; k <= SIZE; k += prime)
  191.                     flags[k] = FALSE;
  192.                 count++;
  193.             }
  194.         }
  195.     }
  196.     printf("%d %d\n", prime, count);
  197. }
  198.  
  199.  
  200.  
  201.  
  202.                        TRS Seive Benchmark
  203.                        C Compiler Analysis
  204.                  February 1985 COMPUTER LANGUAGE
  205.  
  206.  
  207. SIEVE listing used to test LC:
  208. /*  sieve test program for CLM C-compiler comparisons
  209.     Jim Kyle, 6 November 1984
  210.  */
  211. #include stdio/csh
  212. #define size 8190
  213.     char flags[8191];
  214. main()
  215. {
  216.     int i,prime,k,count,iter;
  217.     printf("Start\n");
  218.     for (iter=1; iter <= 10; iter++)  {
  219.         count = 0;
  220.         for (i=0; i <= size; i++)
  221.             flags[i] = TRUE;
  222.         for (i=0; i<= size; i++)      {
  223.             if (flags[i])    {
  224.                 prime = i + i + 3;
  225.                 for (k=i+prime; k <=size; k+=prime)
  226.                     flags[k] = FALSE;
  227.                 count++;
  228.             }
  229.         }
  230.     }
  231.     printf("\nFound %d; stop\n", count);
  232. }
  233. /* END OF PROGRAM */
  234.  
  235.  
  236.  
  237. MYSORT listing used to test LC:
  238. /*    mysort/ccc - integer sorting benchmark, LC */
  239. #include stdio/csh
  240. #define MAX 1000
  241. èint a[MAX], working, jump,i,j,tempo;
  242. main()
  243. {    printf("Initializing array\n");
  244.     for (i=0; i<MAX; ++i)
  245.         a[i] = i;
  246.     jump = MAX;
  247.     printf("Beginning to sort\n");
  248.     while (jump>0)    {
  249.         jump /= 2;
  250.         do    {
  251.             working=FALSE;
  252.             for (j=0; j<(MAX-jump);    ++j)    {
  253.                 i=j+jump;
  254.                 if (a[i] > a[j])    {
  255.                     working=TRUE;
  256.                     tempo=a[i];
  257.                     a[i]=a[j];
  258.                     a[j]=tempo;
  259.                 }
  260.             }
  261.         } while (working);
  262.     }
  263.     printf("Finished sorting\n");
  264.     for (i=0; i<MAX; ++i)
  265.         printf("%d ",a[i]);
  266. }
  267.