00001 #include <iostream> 00002 #include <cassert> 00003 #include <sys/time.h> 00004 #include "timing.hh" 00005 00006 using namespace std; 00007 00008 00009 #if 0 00010 double mysecond() 00011 { 00012 struct timeval tp; 00013 struct timezone tzp; 00014 int i; 00015 00016 i = gettimeofday(&tp,&tzp); 00017 return ( (double) tp.tv_sec + (double) tp.tv_usec * 1.e-6 ); 00018 } 00019 00020 int lIndex=0; 00021 double lStartTime[1024]; 00022 double lEndTime[1024]; 00023 00024 static void tab (int n, ostream& fout) 00025 { 00026 fout << '\n'; 00027 while (n--) fout << '\t'; 00028 } 00029 00030 void startTiming (const char* msg) 00031 { 00032 assert(lIndex < 1023); 00033 tab(lIndex, cerr); cerr << "start " << msg << endl; 00034 lStartTime[lIndex++] = mysecond(); 00035 } 00036 00037 void endTiming (const char* msg) 00038 { 00039 assert(lIndex>0); 00040 lEndTime[--lIndex] = mysecond(); 00041 tab(lIndex, cerr); cerr << "end " << msg << " (duration : " << lEndTime[lIndex] - lStartTime[lIndex] << ")" << endl; 00042 } 00043 00044 #else 00045 00046 void startTiming (const char* msg) 00047 {} 00048 00049 void endTiming (const char* msg) 00050 {} 00051 00052 #endif 00053