Changeset 1847:7cbc12e42482 in lemon-0.x for lemon/time_measure.h
- Timestamp:
- 12/05/05 18:03:31 (18 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2408
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/time_measure.h
r1839 r1847 18 18 #define LEMON_TIME_MEASURE_H 19 19 20 ///\ingroup misc20 ///\ingroup timecount 21 21 ///\file 22 22 ///\brief Tools for measuring cpu usage … … 30 30 namespace lemon { 31 31 32 /// \addtogroup misc32 /// \addtogroup timecount 33 33 /// @{ 34 34 … … 210 210 /// doSomething(); 211 211 /// std::cout << T << '\n'; 212 /// T.res et();212 /// T.restart(); 213 213 /// doSomethingElse(); 214 214 /// std::cout << T << '\n'; … … 224 224 /// 225 225 ///\warning Depending on the operation system and its actual configuration 226 ///the time counters have a certain (relatively big) granularity. 226 ///the time counters have a certain (10ms on a typical Linux system) 227 ///granularity. 227 228 ///Therefore this tool is not appropriate to measure very short times. 228 229 ///Also, if you start and stop the timer very frequently, it could lead … … 239 240 class Timer 240 241 { 241 int running; //Timer is running iff running>0; (running>=0 always holds)242 int _running; //Timer is running iff _running>0; (_running>=0 always holds) 242 243 TimeStamp start_time; //This is the relativ start-time if the timer 243 //is running, the collectedrunning time otherwise.244 245 void _reset() {if( running) start_time.stamp(); else start_time.reset();}244 //is _running, the collected _running time otherwise. 245 246 void _reset() {if(_running) start_time.stamp(); else start_time.reset();} 246 247 247 248 public: … … 250 251 ///\param _running indicates whether or not the timer starts immediately. 251 252 /// 252 Timer(bool _running=true) :running(_running) {_reset();}253 Timer(bool run=true) :_running(run) {_reset();} 253 254 254 255 ///Computes the ellapsed time … … 260 261 TimeStamp t; 261 262 t.stamp(); 262 return running?t-start_time:start_time;263 } 264 265 ///Reset sthe time counters266 267 /// Resets the time counters268 /// 263 return _running?t-start_time:start_time; 264 } 265 266 ///Reset and stop the time counters 267 268 ///This function resets and stops the time counters 269 ///\sa restart() 269 270 void reset() 270 271 { 272 _running=0; 271 273 _reset(); 272 274 } … … 281 283 void start() 282 284 { 283 if( running)running++;285 if(_running) _running++; 284 286 else { 285 287 TimeStamp t; … … 288 290 } 289 291 } 292 290 293 291 294 ///Stop the time counters 292 295 293 ///This function stops the time counters. 294 /// 295 ///\sa stop() 296 ///This function stops the time counters. If start() was executed more than 297 ///once, then the same number of stop() execution is necessary the really 298 ///stop the timer. 299 /// 300 ///\sa halt() 301 ///\sa start() 302 ///\sa restart() 303 ///\sa reset() 304 296 305 void stop() 297 306 { 298 if( running && !--running) {307 if(_running && !--_running) { 299 308 TimeStamp t; 300 309 t.stamp(); … … 302 311 } 303 312 } 313 314 ///Halt (i.e stop immediately) the time counters 315 316 ///This function stops immediately the time counters. 317 /// 318 ///\sa stop() 319 ///\sa restart() 320 ///\sa reset() 321 322 void halt() 323 { 324 if(_running) { 325 _running=0; 326 TimeStamp t; 327 t.stamp(); 328 start_time=t-start_time; 329 } 330 } 331 332 ///Returns the running state of the timer 333 334 ///This function returns the number of stop() exections that is 335 ///necessary to really stop the timer. 336 ///For example the timer 337 ///is running if and only if the return value is \c true 338 ///(i.e. greater than 339 ///zero). 340 int running() { return _running; } 341 342 343 ///Restart the time counters 344 345 ///This function is a shorthand for 346 ///a reset() and a start() calls. 347 /// 348 void restart() 349 { 350 reset(); 351 start(); 352 } 304 353 305 354 ///Gives back the ellapsed user time of the process … … 331 380 }; 332 381 382 ///Same as \ref Timer but prints a report on destruction. 383 384 ///Same as \ref Timer but prints a report on destruction. 385 ///\todo Untested 386 class TimeReport : public Timer 387 { 388 std::string _title; 389 std::ostream &_os; 390 public: 391 ///\e 392 393 TimeReport(std::string title,std::ostream &os,bool run) 394 : Timer(run), _title(title), _os(os){} 395 ~TimeReport() 396 { 397 _os << _title << this << std::endl; 398 } 399 }; 400 333 401 ///Prints the time counters 334 402
Note: See TracChangeset
for help on using the changeset viewer.