home *** CD-ROM | disk | FTP | other *** search
- /* MCHALL10.C
- McHall Test Program
- Designed to run a series of benchmarks against any computer that
- can run a standard ANSI "C" program.
- Version 1.0 12 November 1990.
- */
-
- #include <stdio.h>
- #include <stdlib.h>
- #include <time.h>
-
- int i,j,k;
- int loop,loops;
- long int d1,d2,d3;
- long int dataFileSize = 10000;
- int dat[10000];
- FILE *outfile,*infile;
- time_t tstart,tstop;
- double ttotal;
-
- void initialize(void);
- void generate_test_data(void);
- void display_test_info(void);
- void do_a_loop(void);
-
- main(void)
- {
- float tempf;
-
- initialize();
- generate_test_data();
- display_test_info();
- time(&tstart); /* get start time */
- for(loop=1;loop<loops+1;loop++)
- {
- do_a_loop();
- }
- time(&tstop); /* get stop time */
- printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
- if (!(d1==0x19) || !(d2==0x4e84) || !(d3==0x2742))
- {
- printf("\n ******************* WARNING !!! *****************");
- printf("\n ** Source code has been changed. **");
- printf("\n ** The calculated results do not **");
- printf("\n ** represent the Standard MCHALL !! **");
- printf("\n *************************************************");
- printf("\n\n\n\n");
- }
- printf("Number of loops: %d\n",loops);
- printf("Start time: %s",ctime(&tstart));
- printf(" Stop time: %s",ctime(&tstop));
- ttotal = tstop-tstart; /* get difference */
- tempf = ttotal/loops;
- printf("\nThis machine produces a MCHALL value of %.2f\n\n",tempf);
- printf(" (The tolerance on this reading is +/-%.2f percent due to the\n",
- (0.5/ttotal)*100);
- printf(" resolution of the time-measuring algorithm. A tighter\n");
- printf(" tolerance may be obtained by increasing the number of loops.)");
- return 0;
- }
-
- void initialize(void)
- {
- int i;
- printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
- printf(" Welcome to MCHALL - THE REAL-TIME BENCHMARKER \n\n");
- printf(" (Version 1.0) \n\n");
- printf(" The program runs an operator selectable number of 'loops'.\n");
- printf(" Each loop causes many operations to be performed by the\n");
- printf(" processor. The types of operations have been chosen to\n");
- printf(" represent those typically used in a system application.\n\n");
- printf(" The MCHALL value for a machine is obtained by dividing the\n");
- printf(" total time measured to run the test by the number of loops\n");
- printf(" selected. Therefore, the lower the number, the better the\n");
- printf(" performance of the machine.\n\n\n\n");
- printf(" Enter the number of loops desired (use 1 as a first trial) : ");
- scanf("%d", &loops);
- }
-
- void generate_test_data(void)
- {
- int i;
-
- if ((outfile = fopen("mchall.dat", "wb")) == NULL) /* open outfile */
- {
- printf("\n\n cannot open output file\n");
- exit (1);
- }
- for (i=0; i<dataFileSize; i++) /* create data array */
- dat[i] = i;
- fwrite(dat,sizeof(dat),1,outfile); /* write to data file */
- fclose(outfile); /* close outfile */
- }
-
- void display_test_info(void)
- {
- printf("\n\n\n\n");
- printf(" Each 'loop' of the MCHALL test suite consists of the\n");
- printf(" following tests:\n\n");
- printf(" 1. 10,000 sixteen-bit words are block-read from a file that has\n");
- printf(" been previously created by the program.\n\n");
- printf(" 2. The following arithmetic operations are performed\n");
- printf(" 50,000 times (for each loop):\n\n");
- printf(" 15 Additions or Subtractions\n");
- printf(" 1 Multiplication\n");
- printf(" 3 Divisions\n");
- printf(" 1 Shift\n");
- printf(" 10 Comparisons\n");
- printf(" 10 Branch decisions\n");
- printf("\n\n\n\n");
- }
-
- void do_a_loop(void)
- {
- long int i,j,k,m;
- int ii;
-
- infile = fopen("mchall.dat", "rb"); /* open infile */
- fread(dat,sizeof(dat),1,infile); /* read input file */
- fclose(infile); /* close it */
- printf(" Loop number:%5d",loop);
- printf(" of%5d loops . . . working!\n",loops);
-
- m=0;
- for(i=0;i<5*dataFileSize;i++) /* run thru dataFileSize iterations of following */
- {
- j = dat[i/5]+10101; /* 1 addition 1 division */
- k = j>>1; /* 1 shift */
- m = m+j-k+123; /* 2 additions 1 subtraction */
- m = m + j/3; /* 1 addition 1 division */
- for (ii=0;ii<10;ii++) /* 1 10-stage loop */
- {
- if(m%2 == 0) /* 1 comparison (x10) */
- m=m+1; /* 1 branch decision (x10) */
- else /* 1 add/subtr (x10) */
- m=m-1;
- }
- m = m/3200; /* 1 division */
- m = m * m; /* 1 multiplication */
- /* totals: 15 add/subtr
- 1 multip
- 3 div
- 1 shift
- 10 comparison
- 10 branch decision */
- }
- d1 = m; d2 = j; d3 = k;
- }
-