home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD2.mdf / c / library / dos / timer / mschrt3 / demov3.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-24  |  3.9 KB  |  98 lines

  1. /*---------------------------------------------------------------------------
  2.  |  Program DEMOV3.C                                                        |
  3.  |                                                                          |
  4.  |  This program demonstrates some of the capabilities of MSCHRT            |
  5.  |                                                                          |
  6.  |  (c) 1989 Ryle Design, P.O. Box 22, Mt. Pleasant, Michigan 48804         |
  7.  |                                                                          |
  8.  |  V3.00  Microsoft C Shareware Evaluation Version                         |
  9.  ---------------------------------------------------------------------------*/
  10.  
  11. #include <stdio.h>
  12. #include <conio.h>
  13. #include <math.h>
  14. #include <process.h>
  15.  
  16. #include "pchrt.h"
  17.  
  18. void sin_funct(void)
  19. /*---------------------------------------------------------------------------
  20.  |  A simple function to time.  MSCHRT will tell us how many times this     |
  21.  |  function was called and how much time we spent here.                    |
  22.  |                                                                          |
  23.  |  Globals referenced: none                                                |
  24.  |                                                                          |
  25.  |  Arguments: void                                                         |
  26.  |                                                                          |
  27.  |  Returns: void                                                           |
  28.  ---------------------------------------------------------------------------*/
  29. {
  30.     double  alpha;
  31.  
  32.     t_entry(4);                                             /* start timer 4 */
  33.  
  34.     alpha = sin(2.2734593);                                 /* do something */
  35.  
  36.     t_exit(4);                                              /* stop timer 4 */
  37.  
  38. } /* sin_funct */
  39.  
  40.  
  41.  
  42. void main(void)
  43. {
  44.     char            tstring[25];
  45.     long unsigned   hits, elapsed;
  46.     int             indx;
  47.  
  48.     t_request(5);                                           /* ask for 5 timers */
  49.     if (t_start() != TRUE)                                  /* init MSCHRT first thing */
  50.     {
  51.         printf("Insufficient heap for MSCHRT operation.\n");
  52.         exit(0);
  53.     }
  54.  
  55.     t_entry(0);                                             /* we use timer 0 to time whole run */
  56.  
  57.     printf("MSCHRT V3.00 Demonstration\n\n");
  58.  
  59.     printf("Press any key >> ");
  60.  
  61.     t_entry(2);                                             /* time getch() with timer 2 */
  62.     getch();
  63.     t_exit(2);
  64.  
  65.     t_ask_timer(2,&hits,&elapsed);                          /* get timer 2 results */
  66.  
  67.     printf("\nResponse time was %s\n",t_cvt_time(elapsed,tstring) );
  68.  
  69.     printf("\nCalling sin function with embedded timer 100 times ... ");
  70.     for (indx=0; indx<100; indx++) sin_funct();
  71.     printf("complete\n\n");
  72.  
  73.     printf("Press any key to generate timer reports >> ");
  74.     getche();
  75.     printf("\n");
  76.  
  77.     t_exit(0);                                              /* stop timer timing total run time */
  78.  
  79.     t_set_report(NONZERO);                                  /* specify report type */
  80.     t_rname("NONZERO report type");                         /* report title        */
  81.     t_name(0,"Total run time");                             /* give each timer a name */
  82.     t_name(2,"getch() response");
  83.     t_name(4,"sin() function");
  84.     t_report(0);                                            /* do report - (0) goes to CRT */
  85.  
  86.     t_set_report(HIGHWATER);                                /* request different report type */
  87.     t_rname("HIGHWATER report type");                       /* new name */
  88.     t_report(0);                                            /* do it */
  89.  
  90.     t_stop();                                               /* shut down MSCHRT and free heap */
  91.  
  92.     printf("V3.00 Demo complete\n");                        /* all done ... */
  93.  
  94. } /* main */
  95.  
  96.  
  97.  
  98.