Index: /trunk/SophyaLib/SysTools/ctimer.cc
===================================================================
--- /trunk/SophyaLib/SysTools/ctimer.cc	(revision 3578)
+++ /trunk/SophyaLib/SysTools/ctimer.cc	(revision 3579)
@@ -1,9 +1,13 @@
 //
-// $Id: ctimer.cc,v 1.7 2007-07-06 12:54:12 ansari Exp $
+// $Id: ctimer.cc,v 1.8 2009-02-20 11:07:02 ansari Exp $
 //
 
+#include "machdefs.h"
 #include "sopnamsp.h"
-#include "machdefs.h"
 #include "ctimer.h"
+
+#include <iostream>
+#include <stdio.h>
+#include <string>
 
 //++
@@ -52,5 +56,7 @@
 {
   cpu0 = cpuSplit = clock();
-  elapse0 = elapseSplit = time(0);
+  gettimeofday(&elapse0, NULL);
+  elapseSplit = elapse0;
+//  elapse0 = elapseSplit = time(0);
   cpuSecT = cpuSecP = 0.;
   elapSecT = elapSecP = 0;
@@ -72,12 +78,23 @@
 void Timer::Split(const char* comm, bool prfg)
 {
-  time_t elapse = time(0);
+  struct timeval elapse; 
+  gettimeofday(&elapse, NULL);
+
   clock_t cpu   = clock();
 
-  cpuSecT = ((float)cpu - (float)cpu0) / (float)(CLOCKS_PER_SEC);
-  cpuSecP = ((float)cpu - (float)cpuSplit) / (float)(CLOCKS_PER_SEC);
+  uint_8 deltacpu;
+  if (cpu < cpuSplit) {
+  	clock_t cpumax = 0;   cpumax = ~cpumax;
+  	deltacpu = (uint_8)(cpumax-cpuSplit)+cpu;
+  }
+  else deltacpu = cpu - cpuSplit;
   
-  elapSecP  = elapse - elapseSplit;
-  elapSecT = elapse - elapse0;
+  cpuSecT += ((double)deltacpu) / (double)(CLOCKS_PER_SEC);
+  cpuSecP = ((double)deltacpu) / (double)(CLOCKS_PER_SEC);
+  
+  elapSecP  = (elapse.tv_sec - elapseSplit.tv_sec)*1000  
+              + (elapse.tv_usec - elapseSplit.tv_usec)/1000;
+  elapSecT = (elapse.tv_sec - elapse0.tv_sec)*1000  
+              + (elapse.tv_usec - elapse0.tv_usec)/1000;
 
 
@@ -96,16 +113,27 @@
 // autres C++ que GNU), on fait un cout << chaine.
 
-  int etm  = elapSecP;
-  int etmt = elapSecT; 
-  char out[200];
-  sprintf(out,"CPU     Time: Total= %g (Partial= %g) Sec.",
+  int_4 etm  = elapSecP/1000;
+  int_4 etmt = elapSecT/1000; 
+
+  char out[200],outp[64];
+  sprintf(out,"CPU     Time: Total= %lg (Partial= %lg) s",
 	  cpuSecT, cpuSecP);
   cout << out << endl;
 
-  sprintf(out,"Elapsed Time: Total= %02d:%02d:%02d (Partial=%02d:%02d:%02d)",
-	  etmt/3600, (etmt%3600)/60, etmt%60, 
-	  etm/3600,  (etm%3600)/60,  etm%60);
+  if (etmt<60) {
+    int_4 etmtms = elapSecT%1000; 
+    sprintf(out,"%02d.%03d ms", etmt, etmtms);
+  }
+  else
+    sprintf(out,"%02d:%02d:%02d", etmt/3600, (etmt%3600)/60, etmt%60);
 
-  cout << out << endl;
+  if (etm<60) {
+    int_4 etmms = elapSecT%1000; 
+    sprintf(outp,"%02d.%03d ms", etm, etmms);
+  }
+  else
+    sprintf(outp,"%02d:%02d:%02d", etm/3600, (etm%3600)/60, etm%60);
+        
+  cout << "Elapsed Time: Total=" << out << " (Partial= " << outp << ")" << endl;
 }
 
Index: /trunk/SophyaLib/SysTools/ctimer.h
===================================================================
--- /trunk/SophyaLib/SysTools/ctimer.h	(revision 3578)
+++ /trunk/SophyaLib/SysTools/ctimer.h	(revision 3579)
@@ -1,5 +1,5 @@
 // This may look like C code, but it is really -*- C++ -*-
 //
-// $Id: ctimer.h,v 1.5 2007-07-06 12:54:12 ansari Exp $
+// $Id: ctimer.h,v 1.6 2009-02-20 11:07:02 ansari Exp $
 //
 
@@ -11,7 +11,8 @@
 #include <sys/types.h>
 #include <time.h>
-#include <iostream>
-#include <stdio.h>
+#include <sys/time.h>
 #include <string>
+
+using namespace std;
 
 // <summary> Permet de chronometrer des fonctions. </summary>
@@ -42,24 +43,33 @@
     between the object creation and the last call to Split(). 
   */ 
-  inline int_8 TotalElapsedTime() { return elapSecT ; }
+  inline int_8 TotalElapsedTime() { return elapSecT/1000 ; }
   /*! \brief Return the partial elapsed time (number of seconds).
       between the last two calls to Split().
   */ 
-  inline int_8 PartialElapsedTime() { return elapSecP ; }
+  inline int_8 PartialElapsedTime() { return elapSecP/1000 ; }
+  
+  /*! \brief Return the total elapsed time (in milli-seconds), 
+    between the object creation and the last call to Split(). 
+  */ 
+  inline int_8 TotalElapsedTimems() { return elapSecT ; }
+  /*! \brief Return the partial elapsed time (in milli-seconds).
+      between the last two calls to Split().
+  */ 
+  inline int_8 PartialElapsedTimems() { return elapSecP ; }
 
   /*! \brief Return the total CPU time in seconds, 
     between the object creation and the last call to Split(). 
   */ 
-  inline float TotalCPUTime() { return  cpuSecT; }
+  inline double TotalCPUTime() { return  cpuSecT; }
   /*! \brief Return the partial CPU time in seconds, 
       between the last two calls to Split().
   */ 
-  inline float PartialCPUTime() { return  cpuSecP; }
+  inline double PartialCPUTime() { return  cpuSecP; }
 
 private:
   clock_t cpu0, cpuSplit;
-  time_t  elapse0, elapseSplit;
-  float cpuSecT, cpuSecP;     // Total and partial CPU time 
-  int_8 elapSecT, elapSecP;    // Total and partial elapsed time 
+  struct timeval elapse0, elapseSplit;
+  double cpuSecT, cpuSecP;     // Total and partial CPU time 
+  int_8 elapSecT, elapSecP;    // Total and partial elapsed time in ms
   string timerName;
   bool defprtflg;
