Changeset 209:765619b7cbb2 in lemon-1.2 for lemon/time_measure.h
- Timestamp:
- 07/13/08 20:51:02 (17 years ago)
- Branch:
- default
- Phase:
- public
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/time_measure.h
r157 r209 1 /* -*- C++-*-1 /* -*- mode: C++; indent-tabs-mode: nil; -*- 2 2 * 3 * This file is a part of LEMON, a generic C++ optimization library 3 * This file is a part of LEMON, a generic C++ optimization library. 4 4 * 5 5 * Copyright (C) 2003-2008 … … 65 65 double cstime; 66 66 double rtime; 67 68 void _reset() { 67 68 void _reset() { 69 69 utime = stime = cutime = cstime = rtime = 0; 70 70 } … … 97 97 FILETIME create, exit, kernel, user; 98 98 if (GetProcessTimes(GetCurrentProcess(),&create, &exit, &kernel, &user)) { 99 100 101 102 99 utime = ch * user.dwHighDateTime + cl * user.dwLowDateTime; 100 stime = ch * kernel.dwHighDateTime + cl * kernel.dwLowDateTime; 101 cutime = 0; 102 cstime = 0; 103 103 } else { 104 105 106 107 108 104 rtime = 0; 105 utime = 0; 106 stime = 0; 107 cutime = 0; 108 cstime = 0; 109 109 } 110 #endif 111 } 112 110 #endif 111 } 112 113 113 /// Constructor initializing with zero 114 114 TimeStamp() … … 116 116 ///Constructor initializing with the current time values of the process 117 117 TimeStamp(void *) { stamp();} 118 118 119 119 ///Set every time value to zero 120 120 TimeStamp &reset() {_reset();return *this;} … … 191 191 return t-*this; 192 192 } 193 193 194 194 friend std::ostream& operator<<(std::ostream& os,const TimeStamp &t); 195 195 196 196 ///Gives back the user time of the process 197 197 double userTime() const … … 206 206 ///Gives back the user time of the process' children 207 207 208 ///\note On <tt>WIN32</tt> platform this value is not calculated. 208 ///\note On <tt>WIN32</tt> platform this value is not calculated. 209 209 /// 210 210 double cUserTime() const … … 214 214 ///Gives back the user time of the process' children 215 215 216 ///\note On <tt>WIN32</tt> platform this value is not calculated. 216 ///\note On <tt>WIN32</tt> platform this value is not calculated. 217 217 /// 218 218 double cSystemTime() const … … 224 224 }; 225 225 226 TimeStamp operator*(double b,const TimeStamp &t) 226 TimeStamp operator*(double b,const TimeStamp &t) 227 227 { 228 228 return t*b; 229 229 } 230 230 231 231 ///Prints the time counters 232 232 … … 300 300 TimeStamp start_time; //This is the relativ start-time if the timer 301 301 //is _running, the collected _running time otherwise. 302 302 303 303 void _reset() {if(_running) start_time.stamp(); else start_time.reset();} 304 305 public: 304 305 public: 306 306 ///Constructor. 307 307 … … 332 332 333 333 ///Start the time counters 334 334 335 335 ///This function starts the time counters. 336 336 /// … … 338 338 ///until the same amount of \ref stop() is called. 339 339 ///\sa stop() 340 void start() 340 void start() 341 341 { 342 342 if(_running) _running++; 343 343 else { 344 345 346 347 344 _running=1; 345 TimeStamp t; 346 t.stamp(); 347 start_time=t-start_time; 348 348 } 349 349 } 350 350 351 351 352 352 ///Stop the time counters 353 353 … … 355 355 ///once, then the same number of stop() execution is necessary the really 356 356 ///stop the timer. 357 /// 357 /// 358 358 ///\sa halt() 359 359 ///\sa start() … … 361 361 ///\sa reset() 362 362 363 void stop() 363 void stop() 364 364 { 365 365 if(_running && !--_running) { 366 367 368 366 TimeStamp t; 367 t.stamp(); 368 start_time=t-start_time; 369 369 } 370 370 } … … 384 384 ///\sa reset() 385 385 386 void halt() 386 void halt() 387 387 { 388 388 if(_running) { 389 390 391 392 389 _running=0; 390 TimeStamp t; 391 t.stamp(); 392 start_time=t-start_time; 393 393 } 394 394 } … … 403 403 ///zero). 404 404 int running() { return _running; } 405 406 405 406 407 407 ///Restart the time counters 408 408 … … 410 410 ///a reset() and a start() calls. 411 411 /// 412 void restart() 412 void restart() 413 413 { 414 414 reset(); 415 415 start(); 416 416 } 417 417 418 418 ///@} 419 419 … … 434 434 ///Gives back the ellapsed user time of the process' children 435 435 436 ///\note On <tt>WIN32</tt> platform this value is not calculated. 436 ///\note On <tt>WIN32</tt> platform this value is not calculated. 437 437 /// 438 438 double cUserTime() const … … 442 442 ///Gives back the ellapsed user time of the process' children 443 443 444 ///\note On <tt>WIN32</tt> platform this value is not calculated. 444 ///\note On <tt>WIN32</tt> platform this value is not calculated. 445 445 /// 446 446 double cSystemTime() const … … 488 488 ///\sa NoTimeReport 489 489 ///\todo There is no test case for this 490 class TimeReport : public Timer 490 class TimeReport : public Timer 491 491 { 492 492 std::string _title; … … 499 499 ///\param run Sets whether the timer should start immediately. 500 500 501 TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) 501 TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) 502 502 : Timer(run), _title(title), _os(os){} 503 503 ///\e Prints the ellapsed time on destruction. 504 ~TimeReport() 504 ~TimeReport() 505 505 { 506 506 _os << _title << *this << std::endl; 507 507 } 508 508 }; 509 509 510 510 ///'Do nothing' version of \ref TimeReport 511 511 … … 528 528 void start() {} 529 529 void stop() {} 530 void halt() {} 530 void halt() {} 531 531 int running() { return 0; } 532 532 void restart() {} … … 537 537 double realTime() const { return 0; } 538 538 }; 539 539 540 540 ///Tool to measure the running time more exactly. 541 541 542 542 ///This function calls \c f several times and returns the average 543 543 ///running time. The number of the executions will be choosen in such a way … … 551 551 /// total running time will be written into <tt>*full_time</tt>. 552 552 ///\return The average running time of \c f. 553 553 554 554 template<class F> 555 555 TimeStamp runningTimeTest(F f,double min_time=10,unsigned int *num = NULL, … … 567 567 return full/total; 568 568 } 569 570 /// @} 569 570 /// @} 571 571 572 572
Note: See TracChangeset
for help on using the changeset viewer.