home *** CD-ROM | disk | FTP | other *** search
/ Megazine / Megazine-1.iso / PROGRAMA / C / ZTIMER23 / SRC / ZTIMER / TEST.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1996-02-05  |  2.6 KB  |  104 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) 1993-4 SciTech Software
  13. *
  14. * Filename:        $Workfile:   test.cpp  $
  15. * Version:        $Revision:   1.0  $
  16. *
  17. * Language:        C++ 2.1
  18. * Environment:    MS DOS (IBM PC)
  19. *
  20. * Description:    Test program for the Zen Timer Library C++ interface.
  21. *
  22. * $Date:   05 Feb 1996 14:50:20  $ $Author:   KendallB  $
  23. *
  24. ****************************************************************************/
  25.  
  26. #include <iostream.h>
  27. #include <dos.h>
  28. #include "pmode.h"
  29. #include "ztimer.h"
  30.  
  31. /*-------------------------- Implementation -------------------------------*/
  32.  
  33. int        i,j,k;                                /* NON register variables! */
  34.  
  35. void dummy() {}
  36.  
  37. int main(void)
  38. {
  39.     LZTimer        ltimer;
  40.     ULZTimer    ultimer;
  41.  
  42.     ZTimerInit();
  43.  
  44.     /* Test the long period Zen Timer (we don't check for overflow coz
  45.      * it would take tooooo long!)
  46.      */
  47.  
  48.     cout << endl;
  49.     ultimer.restart();
  50.     ltimer.start();
  51.     for (j = 0; j < 10; j++)
  52.         for (i = 0; i < 20000; i++)
  53.             dummy();
  54.     ltimer.stop();
  55.     ultimer.stop();
  56.     cout << "LCount:  " << ltimer.count() << endl;
  57.     cout << "Time:    " << ltimer << " secs\n";
  58.     cout << "ULCount: " << ultimer.count() << endl;
  59.     cout << "ULTime:  " << ultimer << " secs\n";
  60.  
  61.     cout << endl << "Timing ... \n";
  62.     ultimer.restart();
  63.     ltimer.restart();
  64.     for (j = 0; j < 200; j++)
  65.         for (i = 0; i < 20000; i++)
  66.             dummy();
  67.     ltimer.stop();
  68.     ultimer.stop();
  69.     cout << "LCount:  " << ltimer.count() << endl;
  70.     cout << "Time:    " << ltimer << " secs\n";
  71.     cout << "ULCount: " << ultimer.count() << endl;
  72.     cout << "ULTime:  " << ultimer << " secs\n";
  73.  
  74.     /* Test the lap function of the long period Zen Timer */
  75.  
  76.     cout << endl << "Timing ... \n";
  77.     ultimer.restart();
  78.     ltimer.restart();
  79.     for (j = 0; j < 20; j++) {
  80.         for (k = 0; k < 10; k++)
  81.             for (i = 0; i < 20000; i++)
  82.                 dummy();
  83.         cout << "lap: " << ltimer.lap() << endl;
  84.         }
  85.     ltimer.stop();
  86.     ultimer.stop();
  87.     cout << "LCount:  " << ltimer.count() << endl;
  88.     cout << "Time:    " << ltimer << " secs\n";
  89.     cout << "ULCount: " << ultimer.count() << endl;
  90.     cout << "ULTime:  " << ultimer << " secs\n";
  91.  
  92. #ifdef    LONG_TEST
  93.     /* Test the ultra long period Zen Timer */
  94.  
  95.     ultimer.start();
  96.     delay(DELAY_SECS * 1000);
  97.     ultimer.stop();
  98.     cout << "Delay of " << DELAY_SECS << " secs took " << ultimer.count()
  99.          << " 1/10ths of a second\n";
  100.     cout << "Time: " << ultimer << " secs\n";
  101. #endif
  102.     return 0;
  103. }
  104.