BENCH.CPP 11 KB

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