Changeset 3274 in Sophya for trunk/SophyaLib/SysTools/ctimer.cc
- Timestamp:
- Jul 6, 2007, 2:54:12 PM (18 years ago)
- File:
-
- 1 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 }
Note:
See TracChangeset
for help on using the changeset viewer.