home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pctech / 1988_02 / auto2.c < prev    next >
Text File  |  1985-09-30  |  2KB  |  119 lines

  1. /* auto2.c - individual benchmark tests - (from pentath.c) */
  2. #include "stdio.h"
  3. FILE *fopen() ;
  4.  
  5. int float1()      /* floating point arithmetic benchmark */
  6.  {
  7.     int i , j ;
  8.     float x[100] , y[100] , z ;
  9.  
  10.     for( i=0 ; i < 100 ; i=i+1 )
  11.        { x[i] = i+1 ;
  12.          y[i] = 3*i ;
  13.        } ;
  14.  
  15.     z=0 ;
  16.     for( j=0 ; j < 10 ; j=j+1 )
  17.        { 
  18.          for( i=0 ; i < 100 ; i=i+1 )
  19.             { z = z + x[i]*y[i] ; } ;
  20.        }
  21.  }
  22.  
  23.  
  24.  
  25. int funcall()            /* function calling benchmark */
  26.  {
  27.     int i ;
  28.  
  29.     for( i=0 ; i < 20000 ; i=i+1 )
  30.        { dummy(i) ; } ;
  31.  }
  32.  
  33. int dummy(i)
  34.  int i ;
  35.  {
  36.     return( i+1 ) ;
  37.  }
  38.  
  39.  
  40. int pscopy()     /* pointer based string copy benchmark */
  41.  {
  42.     int i ;
  43.     char s[501] , s2[501] ;
  44.  
  45.     for(i=0 ; i < 500 ; i=i+1 )
  46.        { s[i] = 'a' ; } ;
  47.     s[500] = '\0' ;
  48.  
  49.     for( i=0 ; i < 100 ; i=i+1 )
  50.        { scopy(s2,s) ; } ;
  51.  }
  52.  
  53.          
  54. int scopy(to,from)     /* string copy function */
  55.  char *to ;         /* pointer to destination string */
  56.  char *from ;       /* pointer to source string */
  57.  {
  58.     while( (*to++ = *from++) != '\0' ) /* check for end of string */
  59.       { ; } ; /* copy one char and advance ptrs */
  60.  }
  61.  
  62. int ccount()    /* character count benchmark */
  63.  {
  64.     int i ;
  65.     char s[501] ;
  66.     int cnt[128] ;
  67.  
  68.     for(i=0 ; i < 500 ; i=i+1 )
  69.        { s[i] = i + 1 ; } ;
  70.     s[500] = '\0' ;
  71.  
  72.     for( i=0 ; i < 100 ; i=i+1 )
  73.        { count_chars(s,cnt) ; } ;
  74.  }
  75.  
  76. int count_chars(string,counts)
  77.  char string[] ;
  78.  int counts[] ;
  79.  {
  80.    register int i ;
  81.    register char c ;
  82.  
  83.    i=0 ;
  84.    c = string[i] ;
  85.    while( c != '\0' )
  86.      { counts[ c & 0x7f ] ++ ; 
  87.        i = i + 1 ;
  88.        c = string[i] ;
  89.      } ;
  90.  }
  91.  
  92.  
  93. extern char *inname , *outname ;
  94.  
  95. int gpfile()     /* file copy with getc/putc */
  96.  {
  97.     FILE  *in ,
  98.           *out ;
  99.     int c ;
  100.     long n ;
  101.  
  102.     in = fopen(inname,"r");
  103.     out = fopen(outname,"w");
  104.     if( (in == NULL) || (out ==NULL) )
  105.       { printf("can't open a file");
  106.         exit(0) ;
  107.       }
  108.     n=0;
  109.     c = getc(in) ;
  110.     while( c != EOF )
  111.       { n=n+1 ;
  112.         putc(c,out);
  113.         c = getc(in) ;
  114.       } 
  115.     fclose(in);
  116.     fclose(out);
  117.  }
  118.  
  119.