BENCH.H 4.6 KB

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