CnC_Remastered_Collection

Command and Conquer: Red Alert
Log | Files | Refs | README | LICENSE

BENCH.CPP (10949B)


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