home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / pascal / library / dos / zen / ztimer / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-27  |  2.2 KB  |  98 lines

  1. /****************************************************************************
  2. *
  3. *                                 Zen Timer
  4. *
  5. *                               From the book
  6. *                         "Zen of Assembly Language"
  7. *                            Volume 1, Knowledge
  8. *
  9. *                             by Michael Abrash
  10. *
  11. *                    Simple Test program by Kendall Bennett
  12. *
  13. * Filename:        $RCSfile: main.c $
  14. * Version:        $Revision: 1.1 $
  15. *
  16. * Language:        ANSI C
  17. * Environment:    MS DOS (IBM PC)
  18. *
  19. * Description:    Test program for the Zen Timer Library.
  20. *
  21. * $Id: main.c 1.1 92/01/27 21:43:06 kjb release $
  22. *
  23. * Revision History:
  24. * -----------------
  25. *
  26. * $Log:    main.c $
  27. * Revision 1.1  92/01/27  21:43:06  kjb
  28. * Initial revision
  29. ****************************************************************************/
  30.  
  31. #include <stdio.h>
  32. #include "debug.h"
  33. #include "ztimer.h"
  34.  
  35. /*------------------------- Global variables ------------------------------*/
  36.  
  37. char    *rcsid = "$Id: main.c 1.1 92/01/27 21:43:06 kjb release $";
  38.  
  39. /*-------------------------- Implementation -------------------------------*/
  40.  
  41. /* The following routine takes a long count in microseconds and outputs
  42.  * a string representing the count in seconds. It could be modified to
  43.  * return a pointer to a static string representing the count rather
  44.  * than printing it out.
  45.  */
  46.  
  47. void ReportTime(ulong count)
  48. {
  49.     ulong    secs;
  50.  
  51.     secs = count / 1000000L;
  52.     count = count - secs * 1000000L;
  53.     printf("Time taken: %lu.%06lu seconds\n",secs,count);
  54. }
  55.  
  56. int        i,j;                                /* NON register variables! */
  57.  
  58. int main(void)
  59. {
  60.     ulong    count;
  61.  
  62.     /* Test the precision timer routine */
  63.  
  64.     PZTimerOn();
  65.     for (i = 0; i < 10000; i++)
  66.         i = i;
  67.     PZTimerOff();
  68.     PZTimerReport();
  69.     count = PZTimerCount();
  70.     printf("Count returned: %lu\n",count);
  71.  
  72.     /* Test the precision timer routine for overflow */
  73.  
  74.     PZTimerOn();
  75.     for (j = 0; j < 10; j++)
  76.         for (i = 0; i < 20000; i++)
  77.             i = i;
  78.     PZTimerOff();
  79.     PZTimerReport();
  80.     count = PZTimerCount();
  81.     printf("Count returned: %lu\n",count);
  82.  
  83.     /* Test the long period Zen Timer (we don't check for overflow coz
  84.      * it would take tooooo long!)
  85.      */
  86.  
  87.     LZTimerOn();
  88.     for (j = 0; j < 10; j++)
  89.         for (i = 0; i < 20000; i++)
  90.             i = i;
  91.     LZTimerOff();
  92.     LZTimerReport();
  93.     ReportTime(LZTimerCount());
  94.  
  95.     return 0;
  96. }
  97.