$search
00001 /* 00002 James R. Diebel 00003 Stanford University 00004 00005 Started: 27 August 2004 00006 Last revised: 27 Sugust 2004 00007 00008 timer.cc - class implementation of Timer class (timer.hh) 00009 00010 Depends on timer.hh 00011 */ 00012 00013 #include "bmtk/timer.hh" 00014 00015 namespace bmtk { 00016 00017 Timer::Timer() { 00018 totalTime = storeTime = 0; 00019 } 00020 00021 Timer::Timer(char* prefix_, char* suffix_) { 00022 prefix = prefix_; 00023 suffix = suffix_; 00024 totalTime = storeTime = 0; 00025 } 00026 00027 float Timer::read() { 00028 return float(totalTime)/float(CLOCKS_PER_SEC); 00029 } 00030 00031 float Timer::start() { 00032 startTime = clock(); 00033 return read(); 00034 } 00035 00036 float Timer::stop() { 00037 stopTime = clock(); 00038 totalTime += (stopTime - startTime); 00039 return read(); 00040 } 00041 00042 float Timer::glance() { 00043 stop(); 00044 start(); 00045 return read(); 00046 } 00047 00048 void Timer::reset() { 00049 totalTime = 0; 00050 } 00051 00052 float Timer::peek() { 00053 return float(storeTime)/float(CLOCKS_PER_SEC); 00054 } 00055 00056 float Timer::store() { 00057 storeTime += totalTime; 00058 return peek(); 00059 } 00060 00061 void Timer::resetStore() { 00062 storeTime = 0; 00063 } 00064 00065 void Timer::resetAll() { 00066 reset(); 00067 resetStore(); 00068 } 00069 00070 float Timer::recall() { 00071 totalTime = storeTime; 00072 return read(); 00073 } 00074 00075 float Timer::mark() { 00076 stop(); 00077 float reading = read(); 00078 store(); 00079 reset(); 00080 return reading; 00081 } 00082 00083 float Timer::print() { 00084 cout << prefix << "Timer: " << read() << " seconds" 00085 << suffix << flush; 00086 return read(); 00087 } 00088 00089 float Timer::printGlance() { 00090 float reading = glance(); 00091 cout << prefix << "Timer: " << reading << " seconds" 00092 << suffix << flush; 00093 return reading; 00094 } 00095 00096 float Timer::printStore() { 00097 cout << prefix << "Total time: " << peek() << " seconds" 00098 << suffix << flush; 00099 return peek(); 00100 } 00101 00102 float Timer::printStore(char* label) { 00103 cout << prefix << label << ": " << peek() << " seconds" 00104 << suffix << flush; 00105 return peek(); 00106 } 00107 00108 float Timer::printMark() { 00109 stop(); 00110 float reading = read(); 00111 store(); 00112 reset(); 00113 cout << prefix << "(" << reading << "/" 00114 << peek() << ")" << suffix << flush; 00115 start(); 00116 return reading; 00117 } 00118 00119 float Timer::printMark(char* label) { 00120 stop(); 00121 float reading = read(); 00122 store(); 00123 reset(); 00124 cout << prefix << label << ": " << reading << " seconds of " 00125 << peek() << " seconds in total" << suffix << flush; 00126 start(); 00127 return reading; 00128 } 00129 00130 float Timer::printStop() { 00131 stop(); 00132 float reading = read(); 00133 store(); 00134 reset(); 00135 cout << prefix << reading << " of " 00136 << peek() << suffix << flush; 00137 return reading; 00138 } 00139 00140 float Timer::printStop(char* label) { 00141 stop(); 00142 float reading = read(); 00143 store(); 00144 reset(); 00145 cout << prefix << label << ": " << reading << " seconds of " 00146 << peek() << " seconds in total" << suffix << flush; 00147 return reading; 00148 } 00149 00150 } // namespace bmtk