Changeset 3579 in Sophya for trunk/SophyaLib/SysTools
- Timestamp:
- Feb 20, 2009, 12:07:02 PM (17 years ago)
- Location:
- trunk/SophyaLib/SysTools
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/SophyaLib/SysTools/ctimer.cc
r3274 r3579 1 1 // 2 // $Id: ctimer.cc,v 1. 7 2007-07-06 12:54:12 ansari Exp $2 // $Id: ctimer.cc,v 1.8 2009-02-20 11:07:02 ansari Exp $ 3 3 // 4 4 5 #include "machdefs.h" 5 6 #include "sopnamsp.h" 6 #include "machdefs.h"7 7 #include "ctimer.h" 8 9 #include <iostream> 10 #include <stdio.h> 11 #include <string> 8 12 9 13 //++ … … 52 56 { 53 57 cpu0 = cpuSplit = clock(); 54 elapse0 = elapseSplit = time(0); 58 gettimeofday(&elapse0, NULL); 59 elapseSplit = elapse0; 60 // elapse0 = elapseSplit = time(0); 55 61 cpuSecT = cpuSecP = 0.; 56 62 elapSecT = elapSecP = 0; … … 72 78 void Timer::Split(const char* comm, bool prfg) 73 79 { 74 time_t elapse = time(0); 80 struct timeval elapse; 81 gettimeofday(&elapse, NULL); 82 75 83 clock_t cpu = clock(); 76 84 77 cpuSecT = ((float)cpu - (float)cpu0) / (float)(CLOCKS_PER_SEC); 78 cpuSecP = ((float)cpu - (float)cpuSplit) / (float)(CLOCKS_PER_SEC); 85 uint_8 deltacpu; 86 if (cpu < cpuSplit) { 87 clock_t cpumax = 0; cpumax = ~cpumax; 88 deltacpu = (uint_8)(cpumax-cpuSplit)+cpu; 89 } 90 else deltacpu = cpu - cpuSplit; 79 91 80 elapSecP = elapse - elapseSplit; 81 elapSecT = elapse - elapse0; 92 cpuSecT += ((double)deltacpu) / (double)(CLOCKS_PER_SEC); 93 cpuSecP = ((double)deltacpu) / (double)(CLOCKS_PER_SEC); 94 95 elapSecP = (elapse.tv_sec - elapseSplit.tv_sec)*1000 96 + (elapse.tv_usec - elapseSplit.tv_usec)/1000; 97 elapSecT = (elapse.tv_sec - elapse0.tv_sec)*1000 98 + (elapse.tv_usec - elapse0.tv_usec)/1000; 82 99 83 100 … … 96 113 // autres C++ que GNU), on fait un cout << chaine. 97 114 98 int etm = elapSecP; 99 int etmt = elapSecT; 100 char out[200]; 101 sprintf(out,"CPU Time: Total= %g (Partial= %g) Sec.", 115 int_4 etm = elapSecP/1000; 116 int_4 etmt = elapSecT/1000; 117 118 char out[200],outp[64]; 119 sprintf(out,"CPU Time: Total= %lg (Partial= %lg) s", 102 120 cpuSecT, cpuSecP); 103 121 cout << out << endl; 104 122 105 sprintf(out,"Elapsed Time: Total= %02d:%02d:%02d (Partial=%02d:%02d:%02d)", 106 etmt/3600, (etmt%3600)/60, etmt%60, 107 etm/3600, (etm%3600)/60, etm%60); 123 if (etmt<60) { 124 int_4 etmtms = elapSecT%1000; 125 sprintf(out,"%02d.%03d ms", etmt, etmtms); 126 } 127 else 128 sprintf(out,"%02d:%02d:%02d", etmt/3600, (etmt%3600)/60, etmt%60); 108 129 109 cout << out << endl; 130 if (etm<60) { 131 int_4 etmms = elapSecT%1000; 132 sprintf(outp,"%02d.%03d ms", etm, etmms); 133 } 134 else 135 sprintf(outp,"%02d:%02d:%02d", etm/3600, (etm%3600)/60, etm%60); 136 137 cout << "Elapsed Time: Total=" << out << " (Partial= " << outp << ")" << endl; 110 138 } 111 139 -
trunk/SophyaLib/SysTools/ctimer.h
r3274 r3579 1 1 // This may look like C code, but it is really -*- C++ -*- 2 2 // 3 // $Id: ctimer.h,v 1. 5 2007-07-06 12:54:12 ansari Exp $3 // $Id: ctimer.h,v 1.6 2009-02-20 11:07:02 ansari Exp $ 4 4 // 5 5 … … 11 11 #include <sys/types.h> 12 12 #include <time.h> 13 #include <iostream> 14 #include <stdio.h> 13 #include <sys/time.h> 15 14 #include <string> 15 16 using namespace std; 16 17 17 18 // <summary> Permet de chronometrer des fonctions. </summary> … … 42 43 between the object creation and the last call to Split(). 43 44 */ 44 inline int_8 TotalElapsedTime() { return elapSecT ; }45 inline int_8 TotalElapsedTime() { return elapSecT/1000 ; } 45 46 /*! \brief Return the partial elapsed time (number of seconds). 46 47 between the last two calls to Split(). 47 48 */ 48 inline int_8 PartialElapsedTime() { return elapSecP ; } 49 inline int_8 PartialElapsedTime() { return elapSecP/1000 ; } 50 51 /*! \brief Return the total elapsed time (in milli-seconds), 52 between the object creation and the last call to Split(). 53 */ 54 inline int_8 TotalElapsedTimems() { return elapSecT ; } 55 /*! \brief Return the partial elapsed time (in milli-seconds). 56 between the last two calls to Split(). 57 */ 58 inline int_8 PartialElapsedTimems() { return elapSecP ; } 49 59 50 60 /*! \brief Return the total CPU time in seconds, 51 61 between the object creation and the last call to Split(). 52 62 */ 53 inline floatTotalCPUTime() { return cpuSecT; }63 inline double TotalCPUTime() { return cpuSecT; } 54 64 /*! \brief Return the partial CPU time in seconds, 55 65 between the last two calls to Split(). 56 66 */ 57 inline floatPartialCPUTime() { return cpuSecP; }67 inline double PartialCPUTime() { return cpuSecP; } 58 68 59 69 private: 60 70 clock_t cpu0, cpuSplit; 61 time_telapse0, elapseSplit;62 floatcpuSecT, cpuSecP; // Total and partial CPU time63 int_8 elapSecT, elapSecP; // Total and partial elapsed time 71 struct timeval elapse0, elapseSplit; 72 double cpuSecT, cpuSecP; // Total and partial CPU time 73 int_8 elapSecT, elapSecP; // Total and partial elapsed time in ms 64 74 string timerName; 65 75 bool defprtflg;
Note:
See TracChangeset
for help on using the changeset viewer.