Changeset 3579 in Sophya for trunk/SophyaLib/SysTools/ctimer.cc
- Timestamp:
- Feb 20, 2009, 12:07:02 PM (17 years ago)
- File:
-
- 1 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
Note:
See TracChangeset
for help on using the changeset viewer.