Main Page | Alphabetical List | Compound List | File List | Compound Members | File Members

timer.h

Go to the documentation of this file.
00001 #ifndef TIMER_H
00002 #define TIMER_H
00003 
00004 /****************************************************************************************/
00005 /*  Timer                                                                               */
00006 /*                                                                                      */
00007 /*  Author: Charles Bloom                                                               */
00008 /*  Description: A nice little profiling utility                                        */
00009 /*                                                                                      */
00010 /*  The contents of this file are subject to the Genesis3D Public License               */
00011 /*  Version 1.01 (the "License"); you may not use this file except in                   */
00012 /*  compliance with the License. You may obtain a copy of the License at                */
00013 /*  http://www.genesis3d.com                                                            */
00014 /*                                                                                      */
00015 /*  Software distributed under the License is distributed on an "AS IS"                 */
00016 /*  basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.  See                */
00017 /*  the License for the specific language governing rights and limitations              */
00018 /*  under the License.                                                                  */
00019 /*                                                                                      */
00020 /*  The Original Code is Genesis3D, released March 25, 1999.                            */
00021 /*  Genesis3D Version 1.1 released November 15, 1999                                 */
00022 /*  Copyright (C) 1999 WildTangent, Inc. All Rights Reserved           */
00023 /*                                                                                      */
00024 /****************************************************************************************/
00025 
00026 #include <stdio.h>
00027 #include "tsc.h"
00028 
00029 #ifdef __cplusplus
00030 extern "C" {
00031 #endif
00032 
00033 //{
00034 
00035 extern FILE * timerFP;
00036 extern int timerCount;
00037 extern double time_Master;
00038 
00039 extern void Timer_Start(void);
00040 extern void Timer_Stop(void);
00041 
00042 #ifdef DO_TIMER //}{
00043 
00044 #pragma message("timer ON")
00045 
00046 #define TIMER_VARS(func)        static double time_##func =0.0; static tsc_type tsc_##func##1,tsc_##func##2;
00047 
00048 #define TIMER_P(func)   readTSC(tsc_##func##1)
00049 #define TIMER_Q(func)   do { readTSC(tsc_##func##2); time_##func += diffTSC(tsc_##func##1,tsc_##func##2); } while(0)
00050 
00051 #define TIMER_REPORT(func)      fprintf(timerFP,"%-20s : %1.6f : %2.1f %%\n", (#func) , (time_##func)/(double)timerCount , (time_##func)*100.0/(time_Master) );
00052 
00053 #define TIMER_COUNT()   timerCount++
00054 
00055 #define TIMER_START()   Timer_Start();
00056 #define TIMER_STOP()    Timer_Stop();
00057 
00058 #else   //}{
00059 
00060 #pragma message("timer OFF")
00061 
00062 #define TIMER_VARS(func)
00063 #define TIMER_P(func)
00064 #define TIMER_Q(func)
00065 #define TIMER_REPORT(func)
00066 
00067 #define TIMER_COUNT()
00068 
00069 #define TIMER_START()
00070 #define TIMER_STOP()
00071 
00072 #endif //}{
00073 
00074 /**********
00075 
00076 //example usage:
00077 
00078 TIMER_VARS(test1);
00079 TIMER_VARS(test2);
00080 
00081 int main(int argc,char *argv[])
00082 {
00083 int i,j;
00084 
00085         timerFP = stdout;
00086 
00087         TIMER_START();
00088 
00089                 TIMER_P(test1);
00090 
00091                 for(i=0;i<1000;i++)
00092                 {
00093                         TIMER_P(test2);
00094                         j = 99/(i+1);
00095                         TIMER_Q(test2);
00096                 }
00097                         
00098                 TIMER_Q(test1);
00099 
00100         TIMER_COUNT();
00101         TIMER_STOP();
00102 
00103         TIMER_REPORT(test2);
00104         TIMER_REPORT(test1);
00105 
00106 return 0;
00107 }
00108 
00109 **********/
00110 
00111 //}
00112 
00113 #ifdef __cplusplus
00114 }
00115 #endif
00116 
00117 #endif // TIMER_H
00118 

Generated on Tue Sep 30 12:36:31 2003 for GTestAndEngine by doxygen 1.3.2