home *** CD-ROM | disk | FTP | other *** search
-
-
- The Deref Benchmark
- C Compiler Review
- February 1985 COMPUTER LANGUAGE
-
-
- /*
- ** deref.c -- benchmark program to examine the effeciency
- ** of pointer dereferencing
- */
-
- #define LOOPS 50000 /* how many loops */
- #define BELL 7 /* ASCII bell character */
-
- struct cptr1 {
- char ********************ptr1;
- };
-
- main()
- {
- unsigned i;
- char yekdorb;
- struct cptr1 ********************pointer;
-
- printf("%u loops\n", LOOPS);
-
- for (i = 0; i <= LOOPS; i++)
- yekdorb = ********************
- (********************pointer).ptr1;
-
- printf("%cfinished\n", BELL);
- exit(0);
- }
-
-
-
-
- The Fib Benchmark
- C Compiler Analysis
- February 1985 COMPUTER LANGUAGE
-
-
- /* Fibonacci Number Generator in C */
- #include "STDIO.H"
- #define NTIMES 10 /* number of times to computer Fibonacci value */
-
- #define NUMBER 24 /* biggest that can be computed in 16 bits */
-
-
- void main() /* compute Fibonacci value */
- {
- int i;
- unsigned value, fib();
-
- printf("%d iterations: ", NTIMES);
- for (i = 1; i <= NTIMES; i++)
- value = fib(NUMBER);
- printf("Fibonacci(%d) = %u.\n", NUMBER, value);
- exit(0);
- }
-
- unsigned fib(x) /* compute Fibonacci number recursively */
- int x;
- {
-
- if (x > 2)
- return (fib(x - 1) + fib(x - 2));
- else return (1);
- }
-
-
-
-
-
- The Matrix Benchmark
- C Compiler Analysis
- February 1985 COMPUTER LANGUAGE
-
- /*
- ** Matrix.c -- a benchmark based on the matrix multiplication
- ** program given by Jerry Pournelle in Byte October 1982 p. 254.
- **
- ** Type conversions have been made explicit with casts. Array
- ** and loop indices now start at 0.
- */
-
- #define M 20
- #define N 20
- #define BELL 7
-
- char gup;
- double summ, a[M][N], b[N][M], c[M][M];
-
- main()
- {
-
- summ = 0.0;
- printf("Hit any character to start\n");
- gup = getchar();
-
- filla();
- printf("\nA filled\n");
- fillb();
- printf("\nB filled\n");
- fillc();
- printf("\nC filled\n");
-
- matmult();
- printf("\nMultiplied\n");
- summit();
-
- printf("The sum is: %20f\n", summ);
- putchar(BELL);
- }
-
- filla()
- {
- int i, j;
-
- for (i=0; i < M; i++)
- for (j = 0; j < N; j++)
- a[i][j] = (double) (i+1) + (j+1);
- }
-
- fillb()
- {
- int i, j;
-
- for (i=0; i < N; i++)è for (j = 0; j < M; j++)
- b[i][j] = (double) (int) (((i+1) + (j+1)) / (j+1));
- }
-
- fillc()
- {
- int i, j;
-
- for (i=0; i < M; i++)
- for (j = 0; j < M; j++)
- c[i][j] = (double) 0;
- }
-
- matmult()
- {
- int i, j, k;
-
- for (i = 0; i < M; i++)
- for (j = 0; j < N; j++)
- for (k = 0; k < M; k++)
- c[i][j] = c[i][j] + a[i][k]*b[k][j];
- }
-
- summit()
- {
- int i, j;
-
- for (i = 0; i < M; i++)
- for (j = 0; j < M; j++)
- summ = summ + c[i][j];
- }
-
-
-
-
- Sieve of Eratosthenes Benchmark
- C Compiler Analysis
- February 1985 COMPUTER LANGUAGE
-
-
- /* Eratosthenes Sieve Prime Number Program in C */
- #define TRUE 1
- #define FALSE 0
- #define SIZE 8190
-
- char flags[SIZE+1];
-
- main()
- {
- int i, prime, k, count, iter;
-
- printf("10 iterations.\n");
- for (iter = 1; iter <= 10; iter++) {
- count = 0;
- for (i = 0; i <= SIZE; i++)
- flags[i] = TRUE;
- for (i = 0; i<= SIZE; i++) {
- if (flags[i]) {
- prime = i + i + 3;
- for (k = i + prime; k <= SIZE; k += prime)
- flags[k] = FALSE;
- count++;
- }
- }
- }
- printf("%d %d\n", prime, count);
- }
-
-
-
-
- TRS Seive Benchmark
- C Compiler Analysis
- February 1985 COMPUTER LANGUAGE
-
-
- SIEVE listing used to test LC:
- /* sieve test program for CLM C-compiler comparisons
- Jim Kyle, 6 November 1984
- */
- #include stdio/csh
- #define size 8190
- char flags[8191];
- main()
- {
- int i,prime,k,count,iter;
- printf("Start\n");
- for (iter=1; iter <= 10; iter++) {
- count = 0;
- for (i=0; i <= size; i++)
- flags[i] = TRUE;
- for (i=0; i<= size; i++) {
- if (flags[i]) {
- prime = i + i + 3;
- for (k=i+prime; k <=size; k+=prime)
- flags[k] = FALSE;
- count++;
- }
- }
- }
- printf("\nFound %d; stop\n", count);
- }
- /* END OF PROGRAM */
-
-
-
- MYSORT listing used to test LC:
- /* mysort/ccc - integer sorting benchmark, LC */
- #include stdio/csh
- #define MAX 1000èint a[MAX], working, jump,i,j,tempo;
- main()
- { printf("Initializing array\n");
- for (i=0; i<MAX; ++i)
- a[i] = i;
- jump = MAX;
- printf("Beginning to sort\n");
- while (jump>0) {
- jump /= 2;
- do {
- working=FALSE;
- for (j=0; j<(MAX-jump); ++j) {
- i=j+jump;
- if (a[i] > a[j]) {
- working=TRUE;
- tempo=a[i];
- a[i]=a[j];
- a[j]=tempo;
- }
- }
- } while (working);
- }
- printf("Finished sorting\n");
- for (i=0; i<MAX; ++i)
- printf("%d ",a[i]);
- }