Changeset 3636 in Sophya
- Timestamp:
- May 26, 2009, 10:24:24 PM (16 years ago)
- Location:
- trunk/SophyaLib/SysTools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SysTools/ctimer.cc
r3579 r3636 1 1 // 2 // $Id: ctimer.cc,v 1. 8 2009-02-20 11:07:02ansari Exp $2 // $Id: ctimer.cc,v 1.9 2009-05-26 20:24:23 ansari Exp $ 3 3 // 4 4 5 5 #include "machdefs.h" 6 #include "sopnamsp.h"7 6 #include "ctimer.h" 8 7 … … 46 45 */ 47 46 47 namespace SOPHYA { 48 48 /*! 49 49 \brief Constructor with the specification of a optional name or message … … 76 76 timer name 77 77 */ 78 void Timer::Split (const char* comm, bool prfg)78 void Timer::SplitQ() 79 79 { 80 80 struct timeval elapse; … … 104 104 elapseSplit = elapse; 105 105 cpuSplit = cpu; 106 } 106 107 108 void Timer::Split(const char* comm, bool prfg) 109 { 110 SplitQ(); 107 111 if ( !defprtflg && !prfg ) return; 108 109 112 cout << "***Timing " << (comm ? comm : timerName.c_str()) << endl; 113 Print(cout); 114 } 110 115 111 116 // Pour des formats comme ca, la syntaxe printf est plus agreable. 112 117 // Pour ne pas melanger stdio/iostream (pb de desynchronisation sur 113 118 // autres C++ que GNU), on fait un cout << chaine. 119 120 121 ostream& Timer::Print(ostream& os) const 122 { 114 123 115 124 int_4 etm = elapSecP/1000; … … 119 128 sprintf(out,"CPU Time: Total= %lg (Partial= %lg) s", 120 129 cpuSecT, cpuSecP); 121 cout<< out << endl;130 os << out << endl; 122 131 123 132 if (etmt<60) { 124 133 int_4 etmtms = elapSecT%1000; 125 sprintf(out,"%02d.%03d ms", etmt, etmtms);134 sprintf(out,"%02d.%03d s", etmt, etmtms); 126 135 } 127 136 else … … 130 139 if (etm<60) { 131 140 int_4 etmms = elapSecT%1000; 132 sprintf(outp,"%02d.%03d ms", etm, etmms);141 sprintf(outp,"%02d.%03d s", etm, etmms); 133 142 } 134 143 else 135 144 sprintf(outp,"%02d:%02d:%02d", etm/3600, (etm%3600)/60, etm%60); 136 145 137 cout<< "Elapsed Time: Total=" << out << " (Partial= " << outp << ")" << endl;146 os << "Elapsed Time: Total=" << out << " (Partial= " << outp << ")" << endl; 138 147 } 139 148 149 } // FIN namespace SOPHYA -
trunk/SophyaLib/SysTools/ctimer.h
r3579 r3636 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // 3 // $Id: ctimer.h,v 1. 6 2009-02-20 11:07:02ansari Exp $3 // $Id: ctimer.h,v 1.7 2009-05-26 20:24:24 ansari Exp $ 4 4 // 5 5 … … 13 13 #include <sys/time.h> 14 14 #include <string> 15 #include <iostream> 15 16 16 17 using namespace std; … … 35 36 // Si pas de parametre affiche le nom donne a la creation. 36 37 void Split(const char* comm=0, bool prfg=false); 38 39 //! store partial CPU and elapsed time (no print) 40 void SplitQ(); 37 41 38 42 // Sert a eviter que GNU ne pretende qu'on utilise pas l'objet... … … 67 71 inline double PartialCPUTime() { return cpuSecP; } 68 72 73 //! Print the CPU and elapsed time on os (partial time corresponding to the last call to Split()) 74 ostream& Print(ostream& os) const ; 75 //! Print the CPU and elapsed time on cout 76 inline ostream& Print() const { return Print(cout); } 77 69 78 private: 70 79 clock_t cpu0, cpuSplit; … … 76 85 }; 77 86 87 /*! operator << overloading - Calls SplitQ() and Print() */ 88 inline ostream& operator << (ostream& s, Timer& tm) 89 { tm.SplitQ(); tm.Print(s); return(s); } 90 78 91 } // namespace SOPHYA 79 92
Note:
See TracChangeset
for help on using the changeset viewer.