Changeset 1851:78b5ea23f0f1 in lemon-0.x
- Timestamp:
- 12/06/05 19:44:26 (19 years ago)
- Branch:
- default
- Phase:
- public
- Convert:
- svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2419
- Location:
- lemon
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/counter.h
r1847 r1851 96 96 ///or decrement the counter using operator++ and operator--. 97 97 ///A report is automatically printed on destruction. 98 ///\todo More doc 98 99 class Counter 99 100 { -
lemon/time_measure.h
r1850 r1851 45 45 /// they can be pushed to a stream. 46 46 /// 47 /// In most cases, perhaps \ref Timer class is what you want to use instead. 47 /// In most cases, perhaps the \ref Timer or the \ref TimeReport 48 /// class is what you want to use instead. 48 49 /// 49 50 ///\author Alpar Juttner … … 194 195 } 195 196 197 ///Prints the time counters 198 199 ///Prints the time counters in the following form: 200 /// 201 /// <tt>u: XX.XXs s: XX.XXs cu: XX.XXs cs: XX.XXs real: XX.XXs</tt> 202 /// 203 /// where the values are the 204 /// \li \c u: user cpu time, 205 /// \li \c s: system cpu time, 206 /// \li \c cu: user cpu time of children, 207 /// \li \c cs: system cpu time of children, 208 /// \li \c real: real time. 209 /// \relates TimeStamp 210 inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t) 211 { 212 long cls = sysconf(_SC_CLK_TCK); 213 os << "u: " << double(t.getTms().tms_utime)/cls << 214 "s, s: " << double(t.getTms().tms_stime)/cls << 215 "s, cu: " << double(t.getTms().tms_cutime)/cls << 216 "s, cs: " << double(t.getTms().tms_cstime)/cls << 217 "s, real: " << t.realTime() << "s"; 218 return os; 219 } 220 196 221 ///Class for measuring the cpu time and real time usage of the process 197 222 … … 230 255 ///distorted results. 231 256 /// 232 ///The \ref Timer also counts the number of \ref start() 233 ///executions, and is stops only after the same amount (or more) 234 ///\ref stop() "stop()"s. This can be useful e.g. to compute the running time 235 ///of recursive functions. 257 ///\note If you want to measure the running time of the execution of a certain 258 ///function, consider the usage of \ref TimeReport instead. 236 259 /// 237 260 ///\todo This shouldn't be Unix (Linux) specific. 261 ///\sa TimeReport 238 262 /// 239 263 ///\author Alpar Juttner … … 253 277 Timer(bool run=true) :_running(run) {_reset();} 254 278 255 ///Computes the ellapsed time 256 257 ///This conversion computes the ellapsed time 279 ///\name Control the state of the timer 280 ///Basically a Timer can be either running or stopped, 281 ///but it provides a bit finer control on the execution. 282 ///The \ref Timer also counts the number of \ref start() 283 ///executions, and is stops only after the same amount (or more) 284 ///\ref stop() "stop()"s. This can be useful e.g. to compute the running time 285 ///of recursive functions. 258 286 /// 259 operator TimeStamp () const 260 { 261 TimeStamp t; 262 t.stamp(); 263 return _running?t-start_time:start_time; 264 } 287 288 ///@{ 265 289 266 290 ///Reset and stop the time counters … … 353 377 } 354 378 379 ///@} 380 381 ///\name Query Functions for the ellapsed time 382 383 ///@{ 384 355 385 ///Gives back the ellapsed user time of the process 356 386 double userTime() const … … 378 408 return operator TimeStamp().realTime(); 379 409 } 380 410 ///Computes the ellapsed time 411 412 ///This conversion computes the ellapsed time, therefore you can print 413 ///the ellapsed time like this. 414 ///\code 415 /// Timer T; 416 /// doSomething(); 417 /// std::cout << T << '\n'; 418 ///\endcode 419 operator TimeStamp () const 420 { 421 TimeStamp t; 422 t.stamp(); 423 return _running?t-start_time:start_time; 424 } 425 426 427 ///@} 381 428 }; 382 429 … … 384 431 385 432 ///Same as \ref Timer but prints a report on destruction. 386 ///\todo Untested 433 ///This example shows its usage. 434 ///\code 435 /// void myAlg(ListGraph &g,int n) 436 /// { 437 /// TimeReport TR("Running time of myAlg: "); 438 /// ... //Here comes the algorithm 439 /// } 440 ///\endcode 441 /// 442 ///\sa Timer 443 ///\sa NoTimeReport 444 ///\todo There is no test case for this 387 445 class TimeReport : public Timer 388 446 { … … 391 449 public: 392 450 ///\e 393 394 TimeReport(std::string title,std::ostream &os,bool run) 451 452 ///\param title This text will be printed before the ellapsed time. 453 ///\param os The stream to print the report to. 454 ///\param run Sets whether the timer should start immediately. 455 456 TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) 395 457 : Timer(run), _title(title), _os(os){} 458 ///\e Prints the ellapsed time on destruction. 396 459 ~TimeReport() 397 460 { 398 _os << _title << this << std::endl;461 _os << _title << *this << std::endl; 399 462 } 400 463 }; 401 464 402 ///Prints the time counters 403 404 ///Prints the time counters in the following form: 405 /// 406 /// <tt>u: XX.XXs s: XX.XXs cu: XX.XXs cs: XX.XXs real: XX.XXs</tt> 407 /// 408 /// where the values are the 409 /// \li \c u: user cpu time, 410 /// \li \c s: system cpu time, 411 /// \li \c cu: user cpu time of children, 412 /// \li \c cs: system cpu time of children, 413 /// \li \c real: real time. 414 /// \relates TimeStamp 415 inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t) 416 { 417 long cls = sysconf(_SC_CLK_TCK); 418 os << "u: " << double(t.getTms().tms_utime)/cls << 419 "s, s: " << double(t.getTms().tms_stime)/cls << 420 "s, cu: " << double(t.getTms().tms_cutime)/cls << 421 "s, cs: " << double(t.getTms().tms_cstime)/cls << 422 "s, real: " << t.realTime() << "s"; 423 return os; 424 } 425 426 465 ///'Do nothing' version of \ref TimeReport 466 467 ///\sa TimeReport 468 /// 469 class NoTimeReport 470 { 471 public: 472 ///\e 473 NoTimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) {} 474 ///\e Do nothing. 475 ~NoTimeReport() {} 476 477 operator TimeStamp () const { return TimeStamp(); } 478 void reset() {} 479 void start() {} 480 void stop() {} 481 void halt() {} 482 int running() { return 0; } 483 void restart() {} 484 double userTime() const { return 0; } 485 double systemTime() const { return 0; } 486 double cUserTime() const { return 0; } 487 double cSystemTime() const { return 0; } 488 double realTime() const { return 0; } 489 }; 490 427 491 ///Tool to measure the running time more exactly. 428 492
Note: See TracChangeset
for help on using the changeset viewer.