Timer

Description: A nice little profiling utility

Source file: …\genesis3d\OpenSource\Source\timer.h

Contents:

Functions: Start, Stop

Variables: view

Macros: view

Tutorial: view

Changes for Genesis3D v1.6: None

Variables:

extern FILE * timerFP;

extern int timerCount;

extern double time_Master;

 
Return to Contents

Macros:

#ifdef DO_TIMER 

 
#pragma message("timer ON")
 
#define TIMER_VARS(func) static double time_##func =0.0; static tsc_type tsc_##func##1,tsc_##func##2;
 
#define TIMER_P(func) readTSC(tsc_##func##1)
#define TIMER_Q(func) do { readTSC(tsc_##func##2); time_##func += diffTSC(tsc_##func##1,tsc_##func##2); } while(0)
 
#define TIMER_REPORT(func) fprintf(timerFP,"%-20s : %1.6f : %2.1f %%\n", (#func) , (time_##func)/(double)timerCount , (time_##func)*100.0/(time_Master) );
 
#define TIMER_COUNT() timerCount++
 
#define TIMER_START() Timer_Start();
#define TIMER_STOP() Timer_Stop();
 

#else  

#pragma message("timer OFF")
 
#define TIMER_VARS(func)
#define TIMER_P(func)
#define TIMER_Q(func)
#define TIMER_REPORT(func)
 
#define TIMER_COUNT()
 
#define TIMER_START()
#define TIMER_STOP()

#endif

 

Return to Contents

Tutorial:

 

//example usage:

 

TIMER_VARS(test1);

TIMER_VARS(test2);

 

int main(int argc, char *argv[])

{

int i,j;

  timerFP = stdout;

  TIMER_START();

   TIMER_P(test1);

   for(i=0;i<1000;i++)

  {

   TIMER_P(test2);

   j = 99/(i+1);

   TIMER_Q(test2);

  }

   

  TIMER_Q(test1);

 

 TIMER_COUNT();

 TIMER_STOP();

 

 TIMER_REPORT(test2);

 TIMER_REPORT(test1);

 

return 0;

}

 Return to Contents

Functions:

extern void Timer_Start(void);

 

Return to Contents

extern void Timer_Stop(void);

 
Return to Contents