home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Simtel MSDOS 1992 December
/
simtel1292_SIMTEL_1292_Walnut_Creek.iso
/
msdos
/
pctech
/
feb88.arc
/
PENTATH.C
< prev
next >
Wrap
Text File
|
1983-08-04
|
3KB
|
163 lines
/* Figure 1 - Pentathlon program */
#include "stdio.h"
main()
{
int i , niter ;
int ibench ;
printf("\n benchmark:\n");
scanf("%d",&ibench) ;
printf("\n no. iterations:\n");
scanf("%d",&niter);
for( i=1 ; i <= niter ; i=i+1 )
{
switch( ibench )
{
case 1 : bench1() ; break ;
case 2 : bench2() ; break ;
case 3 : bench3() ; break ;
case 4 : bench4() ; break ;
case 5 : bench5() ; break ;
case 6 : makefile() ; break ;
} ;
} ;
printf("\n thru\n");
}
int bench1() /* floating point arithmetic benchmark */
{
int i , j ;
float x[100] , y[100] , z ;
for( i=0 ; i < 100 ; i=i+1 )
{ x[i] = i+1 ;
y[i] = 3*i ;
} ;
z=0 ;
for( j=0 ; j < 10 ; j=j+1 )
{
for( i=0 ; i < 100 ; i=i+1 )
{ z = z + x[i]*y[i] ; } ;
}
}
int bench2() /* function calling benchmark */
{
int i ;
for( i=0 ; i < 20000 ; i=i+1 )
{ dummy(i) ; } ;
}
int dummy(i)
int i ;
{
return( i+1 ) ;
}
int bench3() /* string copy benchmark */
{
int i ;
char s[501] , s2[501] ;
for(i=0 ; i < 500 ; i=i+1 )
{ s[i] = 'a' ; } ;
s[500] = '\0' ;
for( i=0 ; i < 100 ; i=i+1 )
{ scopy(s2,s) ; } ;
}
int scopy(to,from) /* string copy function */
char *to ; /* pointer to destination string */
char *from ; /* pointer to source string */
{
while( (*to++ = *from++) != '\0' ) /* check for end of string */
{ ; } ; /* copy one char and advance ptrs */
}
int bench4() /* character count benchmark */
{
int i ;
char s[501] ;
int cnt[128] ;
for(i=0 ; i < 500 ; i=i+1 )
{ s[i] = i + 1 ; } ;
s[500] = '\0' ;
for( i=0 ; i < 100 ; i=i+1 )
{ count_chars(s,cnt) ; } ;
}
int count_chars(string,counts)
char string[] ;
int counts[] ;
{
register int i ;
register char c ;
i=0 ;
c = string[i] ;
while( c != '\0' )
{ counts[ c & 0x7f ] ++ ;
i = i + 1 ;
c = string[i] ;
} ;
}
int bench5() /* file copy with getc/putc */
{
FILE *in ,
*out ;
int c ;
long n ;
in = fopen("a:test.in","r");
out = fopen("a:test.out","w");
if( (in == NULL) || (out ==NULL) )
{ printf("can't open a file");
exit(0) ;
}
n=0;
c = getc(in) ;
while( c != EOF )
{ n=n+1 ;
putc(c,out);
c = getc(in) ;
} ;
printf("\n %ld characters",n);
fclose(in);
fclose(out);
}
int makefile() /* create test file */
{
FILE *out ;
long n ;
out = fopen("a:test.in","w");
if( out ==NULL )
{ printf("can't open test file");
exit(0) ;
}
n=0;
for( n=0 ; n < 30000 ; n=n+1 )
{ putc('a',out) ; } ;
fclose(out);
}