home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / ins_msc / imc9106 / hrtimer.c < prev    next >
Text File  |  1991-05-09  |  4KB  |  92 lines

  1. /*********************************************************************
  2. * HRTIMER.C - This program times the execution of two functions that *
  3. * reside in the file TESTFUNC.C. You compile TESTFUNC.C using the    *
  4. * type of optimization you wish to test. However, the switches you   *
  5. * use to compile this file, TIMER.C, and the high-resolution timer   *
  6. * functions in STOPWATC.C should remain constant for all tests.      *
  7. *                                                                    *
  8. * Without opt: cl /Ox TIMER.C STOPWATC.C /Od TESTFUNC.C              *
  9. * With opt   : cl /Ox TIMER.C STOPWATC.C /Ozax TESTFUNC.C            *
  10. *                                                                    *
  11. *********************************************************************/
  12.  
  13. #include <stdio.h>      /* printf(), puts()                         */
  14. #include "stopwatc.h"
  15.  
  16. #define FALSE 0
  17. #define TRUE  0
  18. #define DEF_ITERATIONS   1000L
  19. #define MICROSECONDS     (double)1000000L
  20.  
  21. /*----This macro performs the standard timing loop for all tests----*/
  22. #define TIME_IT( funcname, total )                     \
  23.     for(iterations=setting ; iterations; iterations--) \
  24.         {                                              \
  25.         start = StartTimer();                          \
  26.         funcname;                                      \
  27.         end = StopTimer();                             \
  28.         total += end - start;                          \
  29.         }
  30.  
  31. int  testfunc1(void);
  32. int  testfunc2(void);
  33. void emptyfunc(void);
  34. void cdecl main(int argc, char **argv);
  35.  
  36. /*********************************************************************
  37. * main() - Main body of program HRTIMER.C                            *
  38. *********************************************************************/
  39. void cdecl main(int argc, char **argv)
  40.     {
  41.     ULONG start=0, end=0, control_start=0, control_end=0;
  42.     ULONG iterations, setting=DEF_ITERATIONS;
  43.     UINT def = FALSE;
  44.     double test1=0, test2=0, empty=0, op1, op2;
  45.  
  46.     HRInit( CODETIME );         /* Initialize StopWatch functions   */
  47.  
  48.     /*-------- Get iterations from command line, if given ----------*/
  49.     if (argc < 2)
  50.         def = TRUE;
  51.     else
  52.         {
  53.         if(!atol(argv[1]))
  54.             def = TRUE;
  55.         else
  56.             setting = atol(argv[1]);
  57.         }
  58.  
  59.     /*-------- Show number of iterations on screen -----------------*/
  60.     if(def)
  61.         printf("Testing with default iterations: %lu\n",setting);
  62.     else
  63.         printf("Testing with %lu iterations\n",setting);
  64.  
  65.     /*-------- Determine time required for empty function ----------*/
  66.     puts("Timing empty function...");
  67.     TIME_IT( emptyfunc(), empty );
  68.  
  69.     /*-------- Time the first test function ------------------------*/
  70.     puts("Testing testfunc1...");
  71.     TIME_IT( testfunc1(), test1 );
  72.     op1 = test1 - empty;
  73.  
  74.     /*-------- Time the second test function -----------------------*/
  75.     puts("Testing testfunc2...");
  76.     TIME_IT( testfunc2(), test2 );
  77.     op2 = test2 - empty;
  78.  
  79.     /*-------- Show results ----------------------------------------*/
  80.     printf("Test end:\n");
  81.     printf("Empty function : %04.5f Sec.", empty/COUNTS_PER_SEC);
  82.     printf("  %f uSec. each\n", empty/setting/COUNTS_PER_uSEC );
  83.     printf("testfunc1 Gross: %04.5f Sec.\n", test1/COUNTS_PER_SEC);
  84.     printf("testfunc1 Net  : %04.5f Sec.", op1/COUNTS_PER_SEC);
  85.     printf(", %f uSec. each\n", op1/setting/COUNTS_PER_uSEC);
  86.     printf("testfunc2 Gross: %04.5f Sec.\n", test2/COUNTS_PER_SEC);
  87.     printf("testfunc2 Net  : %04.5f Sec.", op2/COUNTS_PER_SEC);
  88.     printf(", %f uSec. each\n", op2/setting/COUNTS_PER_uSEC);
  89.  
  90.     HRTerm();                     /* Set PIT counter 0 to mode 3    */
  91.     }
  92.