        

    ,      ,    
  TTimer .      
-         
    .   14.1    
 ,    . 
     ,     . 

     14.1.  BENCH.H (  TBench) 

    1:   // bench.h --   TBench 
    2: 
    3:   #ifndef __BENCH_H 
    4:   #define __BENCH_H 1 //   include 
    5: 
    6: #include <classlib\timer.h> 
    7: 
    8: typedef void (* testfn)(void); 
    9:	
    10: class TBench: public TTimer { 
    11: public:	
    12:  TBenchQ: TTimer() { }                                 
    13:  void Benchmark(long numTests, testfn tf); 
    14:  void Report(void); 
    15: }; 
    16:	
    17: #endif // __BENCH_H

     TBench   TTimer.  TBenchO ( 12)  
   TTimer,       
   TBench.   Benchmark() ( 13)  
   numTests,   ,   ,  
tf,    ,     void   
   (. typedef   8).  - ReportO, 
   14,  p .	
      14.2     TBench. 
     ,   
  . 

     14.2.  BENCH.CPP (  TBench) 

    1:	// bench.  --   TBench 
    2: 
    3:	#include <stdio.h> 
    4:	#include "bench. h" 
    5: 
    6:	//    tf  numTests  
    7:	void TBench: : Benchmark (long numTests, testfn tf);
    8:	
    9:	printf( "Running %ld tests", numTests); 
    10:	Reset();   // Reset timer to zero 
    11:	Start() ;   // Start timing 
    12:	while (--numTests >= 0) 
    13:	   (* tf)(); // Call user test function 
    14:	Stop();    // Stop timing 
    15:	puts( "\nTests completed"); 
    16:	} 
    17:	
    18:	//    
    19:	void TBench::Report(void)      
    20:	{
    21:	   double result = Time();
    22:	   if (result < Resolution())	
    23:	      putsC'Results too small for accuracy"); 
    24:	   printf( "Elapsed time == %6f sec. \n", result); 
    25:	}

      7-16  - Benchmark().   
  ,        
  - Reset()  Start(). 
      12-13      , 
     tf.      
 14     - Stop(),  
 .   15     ,   
.


    348  III.   ANSI C++ 

