Changeset 1054:c40a9d94442d in lemon-main
- Timestamp:
- 06/05/12 12:06:28 (12 years ago)
- Branch:
- default
- Phase:
- public
- Location:
- lemon
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/base.cc
r477 r1054 22 22 #include<lemon/tolerance.h> 23 23 #include<lemon/core.h> 24 #include<lemon/time_measure.h> 24 25 namespace lemon { 25 26 … … 32 33 #endif 33 34 35 TimeStamp::Format TimeStamp::_format = TimeStamp::NORMAL; 36 34 37 } //namespace lemon -
lemon/math.h
r877 r1054 66 66 } 67 67 68 ///Round a value to its closest integer 69 inline double round(double r) { 70 return (r > 0.0) ? floor(r + 0.5) : ceil(r - 0.5); 71 } 72 68 73 /// @} 69 74 70 75 } //namespace lemon 71 76 72 #endif //LEMON_ TOLERANCE_H77 #endif //LEMON_MATH_H -
lemon/time_measure.h
r786 r1054 35 35 #include <fstream> 36 36 #include <iostream> 37 #include <lemon/math.h> 37 38 38 39 namespace lemon { … … 64 65 double rtime; 65 66 67 public: 68 ///Display format specifier 69 70 ///\e 71 /// 72 enum Format { 73 /// Reports all measured values 74 NORMAL = 0, 75 /// Only real time and an error indicator is displayed 76 SHORT = 1 77 }; 78 79 private: 80 static Format _format; 81 66 82 void _reset() { 67 83 utime = stime = cutime = cstime = rtime = 0; … … 70 86 public: 71 87 88 ///Set output format 89 90 ///Set output format. 91 /// 92 ///The output format is global for all timestamp instances. 93 static void format(Format f) { _format = f; } 94 ///Retrieve the current output format 95 96 ///Retrieve the current output format 97 /// 98 ///The output format is global for all timestamp instances. 99 static Format format() { return _format; } 100 101 72 102 ///Read the current time values of the process 73 103 void stamp() … … 225 255 inline std::ostream& operator<<(std::ostream& os,const TimeStamp &t) 226 256 { 227 os << "u: " << t.userTime() << 228 "s, s: " << t.systemTime() << 229 "s, cu: " << t.cUserTime() << 230 "s, cs: " << t.cSystemTime() << 231 "s, real: " << t.realTime() << "s"; 257 switch(t._format) 258 { 259 case TimeStamp::NORMAL: 260 os << "u: " << t.userTime() << 261 "s, s: " << t.systemTime() << 262 "s, cu: " << t.cUserTime() << 263 "s, cs: " << t.cSystemTime() << 264 "s, real: " << t.realTime() << "s"; 265 break; 266 case TimeStamp::SHORT: 267 double total = t.userTime()+t.systemTime()+ 268 t.cUserTime()+t.cSystemTime(); 269 os << t.realTime() 270 << "s (err: " << round((t.realTime()-total)/ 271 t.realTime()*10000)/100 272 << "%)"; 273 break; 274 } 232 275 return os; 233 276 } … … 469 512 std::string _title; 470 513 std::ostream &_os; 514 bool _active; 471 515 public: 472 516 ///Constructor … … 476 520 ///\param os The stream to print the report to. 477 521 ///\param run Sets whether the timer should start immediately. 478 TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true) 479 : Timer(run), _title(title), _os(os){} 522 ///\param active Sets whether the report should actually be printed 523 /// on destruction. 524 TimeReport(std::string title,std::ostream &os=std::cerr,bool run=true, 525 bool active=true) 526 : Timer(run), _title(title), _os(os), _active(active) {} 480 527 ///Destructor that prints the ellapsed time 481 528 ~TimeReport() 482 529 { 483 _os << _title << *this << std::endl; 484 } 530 if(_active) _os << _title << *this << std::endl; 531 } 532 533 ///Retrieve the activity status 534 535 ///\e 536 /// 537 bool active() const { return _active; } 538 ///Set the activity status 539 540 /// This function set whether the time report should actually be printed 541 /// on destruction. 542 void active(bool a) { _active=a; } 485 543 }; 486 544
Note: See TracChangeset
for help on using the changeset viewer.