BENCH.CPP 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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.CPP 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.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : 07/17/96 *
  30. * *
  31. * Last Update : July 18, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * Benchmark::Begin -- Start the benchmark operation. *
  36. * Benchmark::Benchmark -- Constructor for the benchmark object. *
  37. * Benchmark::End -- Mark the end of a benchmarked operation *
  38. * Benchmark::Reset -- Clear out the benchmark statistics. *
  39. * Benchmark::Value -- Fetch the current average benchmark time. *
  40. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  41. #include "bench.h"
  42. #include "mpu.h"
  43. /***********************************************************************************************
  44. * Benchmark::Benchmark -- Constructor for the benchmark object. *
  45. * *
  46. * This will construct the benchmark object. *
  47. * *
  48. * INPUT: none *
  49. * *
  50. * OUTPUT: none *
  51. * *
  52. * WARNINGS: none *
  53. * *
  54. * HISTORY: *
  55. * 07/18/1996 JLB : Created. *
  56. *=============================================================================================*/
  57. Benchmark::Benchmark(void) :
  58. Average(0),
  59. Counter(0),
  60. TotalCount(0)
  61. {
  62. }
  63. /***********************************************************************************************
  64. * Benchmark::Reset -- Clear out the benchmark statistics. *
  65. * *
  66. * Use this routine to clear out all the accumulated statistics within this benchmark *
  67. * object. The object is set just as if it was freshly constructed. *
  68. * *
  69. * INPUT: none *
  70. * *
  71. * OUTPUT: none *
  72. * *
  73. * WARNINGS: none *
  74. * *
  75. * HISTORY: *
  76. * 07/18/1996 JLB : Created. *
  77. *=============================================================================================*/
  78. void Benchmark::Reset(void)
  79. {
  80. Average = 0;
  81. Counter = 0;
  82. TotalCount = 0;
  83. }
  84. /***********************************************************************************************
  85. * Benchmark::Begin -- Start the benchmark operation. *
  86. * *
  87. * Call this routine before the operation to be benchmarked is begun. The corresponding *
  88. * End() function must be called after the operation has completed. *
  89. * *
  90. * INPUT: reset -- Should the entire benchmark object be reset at this time as well? *
  91. * *
  92. * OUTPUT: none *
  93. * *
  94. * WARNINGS: The Begin() and End() functions are NOT nestable. *
  95. * *
  96. * HISTORY: *
  97. * 07/18/1996 JLB : Created. *
  98. *=============================================================================================*/
  99. void Benchmark::Begin(bool reset)
  100. {
  101. if (reset) Reset();
  102. Clock = 0;
  103. }
  104. /***********************************************************************************************
  105. * Benchmark::End -- Mark the end of a benchmarked operation *
  106. * *
  107. * This routine is called at the end of the operation that is being benchmarked. It is *
  108. * important to call this routine as soon as possible after the event being benchmarked *
  109. * has completed. *
  110. * *
  111. * INPUT: none *
  112. * *
  113. * OUTPUT: none *
  114. * *
  115. * WARNINGS: The Being() and End() functions are NOT nestable. *
  116. * *
  117. * HISTORY: *
  118. * 07/18/1996 JLB : Created. *
  119. *=============================================================================================*/
  120. void Benchmark::End(void)
  121. {
  122. unsigned long value = Clock;
  123. if (Counter == MAXIMUM_EVENT_COUNT) {
  124. Average -= Average / MAXIMUM_EVENT_COUNT;
  125. Average += value;
  126. } else {
  127. Average += value;
  128. Counter++;
  129. }
  130. TotalCount++;
  131. }
  132. /***********************************************************************************************
  133. * Benchmark::Value -- Fetch the current average benchmark time. *
  134. * *
  135. * This routine will take the statistics already accumulated and determine the average *
  136. * time recorded. This value will be returned. *
  137. * *
  138. * INPUT: none *
  139. * *
  140. * OUTPUT: Returns with the average time that all events tracked by this object. *
  141. * *
  142. * WARNINGS: none *
  143. * *
  144. * HISTORY: *
  145. * 07/18/1996 JLB : Created. *
  146. *=============================================================================================*/
  147. unsigned long Benchmark::Value(void) const
  148. {
  149. if (Counter) {
  150. return(Average / Counter);
  151. }
  152. return(0);
  153. }