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