home *** CD-ROM | disk | FTP | other *** search
/ Megazine / Megazine-1.iso / PROGRAMA / C / ZTIMER23 / SRC / ZTIMER / TESTC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-05  |  1.9 KB  |  83 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. *                    Copyright (C) 1996 SciTech Software
  13. *
  14. * Filename:        $Workfile:   testc.c  $
  15. * Version:        $Revision:   1.0  $
  16. *
  17. * Language:        ANSI C
  18. * Environment:    MS DOS (IBM PC)
  19. *
  20. * Description:    Test program for the Zen Timer Library.
  21. *
  22. * $Date:   05 Feb 1996 14:50:20  $ $Author:   KendallB  $
  23. *
  24. ****************************************************************************/
  25.  
  26. #include <stdio.h>
  27. #include <dos.h>
  28. #include "pmode.h"
  29. #include "debug.h"
  30. #include "ztimer.h"
  31.  
  32. #define    DELAY_SECS    10
  33.  
  34. /*-------------------------- Implementation -------------------------------*/
  35.  
  36. /* The following routine takes a long count in microseconds and outputs
  37.  * a string representing the count in seconds. It could be modified to
  38.  * return a pointer to a static string representing the count rather
  39.  * than printing it out.
  40.  */
  41.  
  42. void ReportTime(ulong count)
  43. {
  44.     ulong    secs;
  45.  
  46.     secs = count / 1000000L;
  47.     count = count - secs * 1000000L;
  48.     printf("Time taken: %lu.%06lu seconds\n",secs,count);
  49. }
  50.  
  51. int        i,j;                                /* NON register variables! */
  52.  
  53. int main(void)
  54. {
  55. #ifdef    LONG_TEST
  56.     ulong    start,finish;
  57. #endif
  58.  
  59.     ZTimerInit();
  60.  
  61.     /* Test the long period Zen Timer (we don't check for overflow coz
  62.      * it would take tooooo long!)
  63.      */
  64.  
  65.     LZTimerOn();
  66.     for (j = 0; j < 10; j++)
  67.         for (i = 0; i < 20000; i++)
  68.             i = i;
  69.     LZTimerOff();
  70.     ReportTime(LZTimerCount());
  71.  
  72.     /* Test the ultra long period Zen Timer */
  73. #ifdef LONG_TEST
  74.     start = ULZReadTime();
  75.     delay(DELAY_SECS * 1000);
  76.     finish = ULZReadTime();
  77.     printf("Delay of %d secs took %d 1/10ths of a second\n",
  78.         DELAY_SECS,ULZElapsedTime(start,finish));
  79. #endif
  80.  
  81.     return 0;
  82. }
  83.