home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / BENCHMAR / MCHALL10.ZIP / MCHALL10.C next >
Encoding:
C/C++ Source or Header  |  1990-11-12  |  5.3 KB  |  149 lines

  1. /*  MCHALL10.C
  2.     McHall Test Program
  3.     Designed to run a series of benchmarks against any computer that
  4.       can run a standard ANSI "C" program.
  5.     Version 1.0  12 November 1990.
  6. */
  7.  
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <time.h>
  11.  
  12. int    i,j,k;
  13. int    loop,loops;
  14. long int        d1,d2,d3;
  15. long int    dataFileSize = 10000;
  16. int    dat[10000];
  17. FILE     *outfile,*infile;
  18. time_t    tstart,tstop;
  19. double    ttotal;
  20.  
  21. void initialize(void);
  22. void generate_test_data(void);
  23. void display_test_info(void);
  24. void do_a_loop(void);
  25.  
  26. main(void)
  27. {
  28.   float        tempf;
  29.  
  30.   initialize();
  31.   generate_test_data();
  32.   display_test_info();
  33.   time(&tstart);                     /* get start time */
  34.   for(loop=1;loop<loops+1;loop++)
  35.   {
  36.     do_a_loop();
  37.   }
  38.   time(&tstop);                  /* get stop time */
  39.   printf("\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n");
  40.   if (!(d1==0x19) || !(d2==0x4e84) || !(d3==0x2742))
  41.   {
  42.     printf("\n           ******************* WARNING !!! *****************");
  43.     printf("\n           **       Source code has been changed.         **");
  44.     printf("\n           **       The calculated results do not         **");
  45.     printf("\n           **       represent the Standard MCHALL !!      **");
  46.     printf("\n           *************************************************");
  47.     printf("\n\n\n\n");
  48.   }
  49.   printf("Number of loops:  %d\n",loops);
  50.   printf("Start time:  %s",ctime(&tstart));
  51.   printf(" Stop time:  %s",ctime(&tstop));
  52.   ttotal = tstop-tstart;      /* get difference */
  53.   tempf = ttotal/loops;
  54.   printf("\nThis machine produces a MCHALL value of %.2f\n\n",tempf);
  55.   printf("  (The tolerance on this reading is +/-%.2f percent due to the\n",
  56.          (0.5/ttotal)*100);
  57.   printf("   resolution of the time-measuring algorithm.  A tighter\n");
  58.   printf("   tolerance may be obtained by increasing the number of loops.)");
  59.   return 0;
  60. }
  61.  
  62. void initialize(void)
  63. {
  64.   int    i;
  65.   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");
  66.   printf("          Welcome to  MCHALL - THE REAL-TIME BENCHMARKER \n\n");
  67.   printf("                        (Version 1.0)               \n\n");
  68.   printf("     The program runs an operator selectable number of 'loops'.\n");
  69.   printf("     Each loop causes many operations to be performed by the\n");
  70.   printf("       processor.  The types of operations have been chosen to\n");
  71.   printf("       represent those typically used in a system application.\n\n");
  72.   printf("     The MCHALL value for a machine is obtained by dividing the\n");
  73.   printf("       total time measured to run the test by the number of loops\n");
  74.   printf("       selected.  Therefore, the lower the number, the better the\n");
  75.   printf("       performance of the machine.\n\n\n\n");
  76.   printf("  Enter the number of loops desired (use 1 as a first trial) :   ");
  77.   scanf("%d", &loops);
  78. }
  79.  
  80. void generate_test_data(void)
  81. {
  82.   int    i;
  83.  
  84.   if ((outfile = fopen("mchall.dat", "wb")) == NULL)    /* open outfile */
  85.   {
  86.     printf("\n\n cannot open output file\n");
  87.     exit (1);
  88.   }
  89.   for (i=0; i<dataFileSize; i++)             /* create data array */
  90.      dat[i] = i;
  91.   fwrite(dat,sizeof(dat),1,outfile);         /* write to data file */
  92.   fclose(outfile);                               /* close outfile */
  93. }
  94.  
  95. void display_test_info(void)
  96. {
  97.   printf("\n\n\n\n");
  98.   printf("  Each 'loop' of the MCHALL test suite consists of the\n");
  99.   printf("     following tests:\n\n");
  100.   printf("  1.  10,000 sixteen-bit words are block-read from a file that has\n");
  101.   printf("        been previously created by the program.\n\n");
  102.   printf("  2.  The following arithmetic operations are performed\n");
  103.   printf("        50,000 times (for each loop):\n\n");
  104.   printf("           15  Additions or Subtractions\n");
  105.   printf("            1  Multiplication\n");
  106.   printf("            3  Divisions\n");
  107.   printf("            1  Shift\n");
  108.   printf("           10  Comparisons\n");
  109.   printf("           10  Branch decisions\n");
  110.   printf("\n\n\n\n");
  111. }
  112.  
  113. void do_a_loop(void)
  114. {
  115.   long int     i,j,k,m;
  116.   int           ii;
  117.  
  118.   infile = fopen("mchall.dat", "rb");    /* open infile */
  119.   fread(dat,sizeof(dat),1,infile);        /*  read input file  */
  120.   fclose(infile);                         /*  close it  */
  121.   printf(" Loop number:%5d",loop);
  122.   printf("  of%5d loops   .  .  .  working!\n",loops);
  123.  
  124.   m=0;
  125.   for(i=0;i<5*dataFileSize;i++)             /*  run thru dataFileSize                          iterations of following */
  126.   {
  127.     j = dat[i/5]+10101;     /*  1 addition  1 division  */
  128.     k = j>>1;                   /*  1 shift                          */
  129.     m = m+j-k+123;              /*  2 additions  1 subtraction       */
  130.     m = m + j/3;                /*  1 addition   1 division          */
  131.     for (ii=0;ii<10;ii++)        /*  1 10-stage loop                  */
  132.     {
  133.       if(m%2 == 0)                /*  1 comparison (x10)             */
  134.     m=m+1;                    /*  1 branch decision (x10)        */
  135.       else                        /*  1 add/subtr (x10)              */
  136.     m=m-1;
  137.     }
  138.     m = m/3200;                 /*  1 division                       */
  139.     m = m * m;                  /*  1 multiplication                 */
  140.               /*  totals:   15 add/subtr
  141.                      1 multip
  142.                      3 div
  143.                      1 shift
  144.                     10 comparison
  145.                     10 branch decision   */
  146.   }
  147.   d1 = m;  d2 = j;  d3 = k;
  148. }
  149.