home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / pcmagazi / 1988 / 15 / divtest.c < prev    next >
C/C++ Source or Header  |  1988-06-28  |  1KB  |  49 lines

  1. /* divtest.c RHS 5/18/88
  2.  *
  3.  * This program reports the time to execute a loop with a long divide
  4.  * operation in it.
  5.  *
  6.  *   To compile for MSC 5.x:
  7.  *        cl /W3 /Od divtest.c
  8.  */
  9.  
  10. #define ITERATIONS 100000L
  11. #define DIVIDEND    1000L
  12. #include<time.h>
  13. #include<stdio.h>
  14.  
  15. void main(void);              /* function prototype */
  16.  
  17. void main(void)
  18. {
  19.      long i,start,end,temp;
  20.      float loop,expr;
  21.  
  22.      start = clock();
  23.  
  24.      for( i = 0L; i < ITERATIONS; i++)  /* time the operation    */
  25.           temp = (i/DIVIDEND);          /* divide is tested here */
  26.  
  27.      end = clock();
  28.  
  29.      expr = (float)(end-start);
  30.  
  31.      expr /= CLK_TCK;
  32.  
  33.      printf("\nLoop with Operation time = %04.04f seconds",expr);
  34.  
  35.      start = clock();
  36.  
  37.      for( i = 0L; i < ITERATIONS; i++); /* time the loop alone */
  38.           temp = i;
  39.  
  40.      end = clock();
  41.  
  42.      loop = (float)(end-start);
  43.      loop /= CLK_TCK;
  44.  
  45.      printf("\nLoop                time = %04.04f seconds",loop);
  46.  
  47.      printf("\n\nOperation Overhead       = %04.04f seconds",expr-loop);
  48. }
  49.