BENCH.H 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. /*
  2. ** Command & Conquer Red Alert(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /* $Header: /CounterStrike/BENCH.H 1 3/03/97 10:24a Joe_bostic $ */
  19. /***********************************************************************************************
  20. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  21. ***********************************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : BENCH.H *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : 07/17/96 *
  30. * *
  31. * Last Update : July 17, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36. #ifndef BENCH_H
  37. #define BENCH_H
  38. #include "mpu.h"
  39. #include "ftimer.h"
  40. /*
  41. ** The "bool" integral type was defined by the C++ committee in
  42. ** November of '94. Until the compiler supports this, use the following
  43. ** definition.
  44. */
  45. #ifndef __BORLANDC__
  46. #ifndef TRUE_FALSE_DEFINED
  47. #define TRUE_FALSE_DEFINED
  48. enum {false=0,true=1};
  49. typedef int bool;
  50. #endif
  51. #endif
  52. /*
  53. ** This is a timer access object that will fetch the internal Pentium
  54. ** clock value.
  55. */
  56. class PentiumTimerClass
  57. {
  58. public:
  59. unsigned long operator () (void) const {unsigned long h;unsigned long l = Get_CPU_Clock(h);return((l >> 4) | (h << 28));}
  60. operator unsigned long (void) const {unsigned long h;unsigned long l = Get_CPU_Clock(h);return((l >> 4) | (h << 28));}
  61. };
  62. /*
  63. ** A performance tracking tool object. It is used to track elapsed time. Unlike a simple clock, this
  64. ** class will keep a running average of the duration. Typical use of this would be to benchmark some
  65. ** process that occurs multiple times. By benchmarking an average time, inconsistencies in a particular
  66. ** run can be overcome.
  67. */
  68. class Benchmark
  69. {
  70. public:
  71. Benchmark(void);
  72. void Begin(bool reset=false);
  73. void End(void);
  74. void Reset(void);
  75. unsigned long Value(void) const;
  76. unsigned long Count(void) const {return(TotalCount);}
  77. private:
  78. /*
  79. ** The maximum number of events to keep running average of. If
  80. ** events exceed this number, then older events drop off the
  81. ** accumulated time. This number needs to be as small as
  82. ** is reasonable. The larger this number gets, the less magnitude
  83. ** that the benchmark timer can handle. Example; At a value of
  84. ** 256, the magnitude of the timer can only be 24 bits.
  85. */
  86. enum {MAXIMUM_EVENT_COUNT=256};
  87. /*
  88. ** This is the timer the is used to clock the events.
  89. */
  90. BasicTimerClass<PentiumTimerClass> Clock;
  91. /*
  92. ** The total time off all events tracked so far.
  93. */
  94. unsigned long Average;
  95. /*
  96. ** The total number of events tracked so far.
  97. */
  98. unsigned long Counter;
  99. /*
  100. ** Absolute total number of events (possibly greater than the
  101. ** number of events tracked in the average).
  102. */
  103. unsigned long TotalCount;
  104. };
  105. #endif