Changeset 3274 in Sophya for trunk/SophyaLib/SysTools
- Timestamp:
- Jul 6, 2007, 2:54:12 PM (18 years ago)
- Location:
- trunk/SophyaLib/SysTools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SysTools/ctimer.cc
r2615 r3274 1 1 // 2 // $Id: ctimer.cc,v 1. 6 2004-09-10 09:54:57 cmvExp $2 // $Id: ctimer.cc,v 1.7 2007-07-06 12:54:12 ansari Exp $ 3 3 // 4 4 … … 23 23 // courante comme message. Le temps écoulé sera affiché à la sortie 24 24 // de la function. 25 // * SPLITTIME affiche le temps partiel du compteur crée par TIMEF26 // * TIMEN(nom) permet de donner un autre nom que le nom de la fonction.27 25 //-- 28 26 29 27 30 //++31 // Titre Constructeurs32 //--33 34 //++35 // Timer::Timer(const char* name)36 // Crée un objet qui mémorise l'heure et le temps CPU du process courant.37 // Le destructeur affiche les temps écoulé et CPU utilisé.38 //--39 28 40 29 /*! … … 45 34 measuring the CPU and elapsed time in functions. The constructor 46 35 keeps the start time (and CPU time) and an optional message. 47 The \b Split method displays the partial time, and destructor 36 The \b Split updates partial times and optionaly displays partial and 37 total CPU and elapsed time. 38 The destructor calls Split() if the object has been created with prfg=true. 48 39 displays the total CPU and elapsed time since timer creation. 49 40 The macro \b TIMEF create a timer object with the function name. 50 The macro \b SPLITTIME calls the split methode for the timer created 51 by TIMEF. A named timer can be created using the macro \b TIMEN(nom) 41 The elapsed and CPU time are displayed at the end of the bloc or function. 52 42 */ 53 43 54 /*! Constructor with the specification of a optional name or message */ 55 Timer::Timer(const char* name) 56 : timerName(name) 44 /*! 45 \brief Constructor with the specification of a optional name or message 46 and default print flag. 47 if \b prfg==true , a call to Split() causes the display of partial and 48 total CPU and elapsed time. 49 */ 50 Timer::Timer(const char* name, bool prfg) 51 : timerName(name) , defprtflg(prfg) 57 52 { 58 53 cpu0 = cpuSplit = clock(); 59 54 elapse0 = elapseSplit = time(0); 55 cpuSecT = cpuSecP = 0.; 56 elapSecT = elapSecP = 0; 60 57 } 61 58 62 //++ 63 // Titre Méthodes 64 //-- 59 //! The destructor call Split() if the object has been created with prtflag=true. 60 Timer::~Timer() 61 { 62 if (defprtflg) Split(); 63 } 65 64 66 //++67 // Timer::Split(const char* comm)68 // Affiche le temps partiel.69 //--70 65 71 /*! Method which displays the partial CPU and elapsed time 66 /*! This method updates the CPU and elapsed time. 67 If the prfg==true or the constructor prfg==true, it also displays (prints) 68 the partial CPU and elapsed time 72 69 An optional message can be passed to be used instead of the 73 70 timer name 74 71 */ 75 void Timer::Split(const char* comm )72 void Timer::Split(const char* comm, bool prfg) 76 73 { 77 74 time_t elapse = time(0); 78 75 clock_t cpu = clock(); 79 76 80 floatcpuSecT = ((float)cpu - (float)cpu0) / (float)(CLOCKS_PER_SEC);81 floatcpuSecP = ((float)cpu - (float)cpuSplit) / (float)(CLOCKS_PER_SEC);77 cpuSecT = ((float)cpu - (float)cpu0) / (float)(CLOCKS_PER_SEC); 78 cpuSecP = ((float)cpu - (float)cpuSplit) / (float)(CLOCKS_PER_SEC); 82 79 83 int etm = elapse - elapseSplit; 84 int etmt = elapse - elapse0; 80 elapSecP = elapse - elapseSplit; 81 elapSecT = elapse - elapse0; 82 83 84 // cumlcpu += (double)cpuSecP; 85 // cumulelapse += (int_8)etm; 86 87 elapseSplit = elapse; 88 cpuSplit = cpu; 89 90 if ( !defprtflg && !prfg ) return; 85 91 86 92 cout << "***Timing " << (comm ? comm : timerName.c_str()) << endl; … … 90 96 // autres C++ que GNU), on fait un cout << chaine. 91 97 98 int etm = elapSecP; 99 int etmt = elapSecT; 92 100 char out[200]; 93 101 sprintf(out,"CPU Time: Total= %g (Partial= %g) Sec.", … … 100 108 101 109 cout << out << endl; 102 103 elapseSplit = elapse;104 cpuSplit = cpu;105 110 } 106 111 107 Timer::~Timer()108 {109 Split();110 } -
trunk/SophyaLib/SysTools/ctimer.h
r2322 r3274 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // 3 // $Id: ctimer.h,v 1. 4 2003-02-11 15:31:07 cmvExp $3 // $Id: ctimer.h,v 1.5 2007-07-06 12:54:12 ansari Exp $ 4 4 // 5 5 … … 16 16 17 17 // <summary> Permet de chronometrer des fonctions. </summary> 18 // La macro TIMEF cree un objet de class Timer qui memorise 19 // l'heure de sa creation, et le temps CPU. 20 18 // Class Timer qui memorise l'heure de sa creation, et le temps CPU. 21 19 // A la fin du bloc ou de la procedure, l'objet est detruit, 22 20 // et son destructeur affiche le temps ecoule. 23 21 24 // La macro SPLITTIME lui permet d'afficher des temps partiels.25 22 namespace SOPHYA { 26 23 … … 29 26 public: 30 27 // L'objet memorise le temps CPU et l'heure, et le nom donne 31 Timer(const char* name=0 );28 Timer(const char* name=0, bool prfg=true); 32 29 33 30 // Le destructeur appelle split sans parametre. … … 36 33 // Affiche le temps ecoule total/partiel, avec le nom eventuel. 37 34 // Si pas de parametre affiche le nom donne a la creation. 38 void Split(const char* comm=0 );35 void Split(const char* comm=0, bool prfg=false); 39 36 40 37 // Sert a eviter que GNU ne pretende qu'on utilise pas l'objet... … … 42 39 void Nop() {} 43 40 41 /*! \brief Return the total elapsed time (number of seconds), 42 between the object creation and the last call to Split(). 43 */ 44 inline int_8 TotalElapsedTime() { return elapSecT ; } 45 /*! \brief Return the partial elapsed time (number of seconds). 46 between the last two calls to Split(). 47 */ 48 inline int_8 PartialElapsedTime() { return elapSecP ; } 49 50 /*! \brief Return the total CPU time in seconds, 51 between the object creation and the last call to Split(). 52 */ 53 inline float TotalCPUTime() { return cpuSecT; } 54 /*! \brief Return the partial CPU time in seconds, 55 between the last two calls to Split(). 56 */ 57 inline float PartialCPUTime() { return cpuSecP; } 58 44 59 private: 45 60 clock_t cpu0, cpuSplit; 46 61 time_t elapse0, elapseSplit; 62 float cpuSecT, cpuSecP; // Total and partial CPU time 63 int_8 elapSecT, elapSecP; // Total and partial elapsed time 47 64 string timerName; 65 bool defprtflg; 48 66 }; 49 67 50 68 } // namespace SOPHYA 51 69 52 #define TIMEN(x) Timer timer(x); timer.Nop(); 53 #define TIMEF Timer timer(__PRETTY_FUNCTION__); timer.Nop(); 54 #define SPLITTIME timer.Split(); 70 #define TIMEF Timer timer(__PRETTY_FUNCTION__); timer.Nop(); 55 71 56 72 #endif // CTIMER_SEEN
Note:
See TracChangeset
for help on using the changeset viewer.