Changeset 3636 in Sophya


Ignore:
Timestamp:
May 26, 2009, 10:24:24 PM (16 years ago)
Author:
ansari
Message:

Petites correction/amelioration de la classe Timer - Reza 26/05/2009

Location:
trunk/SophyaLib/SysTools
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/SophyaLib/SysTools/ctimer.cc

    r3579 r3636  
    11//
    2 // $Id: ctimer.cc,v 1.8 2009-02-20 11:07:02 ansari Exp $
     2// $Id: ctimer.cc,v 1.9 2009-05-26 20:24:23 ansari Exp $
    33//
    44
    55#include "machdefs.h"
    6 #include "sopnamsp.h"
    76#include "ctimer.h"
    87
     
    4645*/
    4746
     47namespace SOPHYA {
    4848/*!
    4949  \brief Constructor with the specification of a optional name or message
     
    7676    timer name
    7777*/
    78 void Timer::Split(const char* comm, bool prfg)
     78void Timer::SplitQ()
    7979{
    8080  struct timeval elapse;
     
    104104  elapseSplit = elapse;
    105105  cpuSplit    = cpu;
     106}
    106107
     108void Timer::Split(const char* comm, bool prfg)
     109{
     110  SplitQ();
    107111  if ( !defprtflg && !prfg )  return;
    108 
    109112  cout << "***Timing " << (comm ? comm : timerName.c_str()) << endl;
     113  Print(cout);
     114}
    110115
    111116// Pour des formats comme ca, la syntaxe printf est plus agreable.
    112117// Pour ne pas melanger stdio/iostream (pb de desynchronisation sur
    113118// autres C++ que GNU), on fait un cout << chaine.
     119
     120
     121ostream& Timer::Print(ostream& os) const
     122{
    114123
    115124  int_4 etm  = elapSecP/1000;
     
    119128  sprintf(out,"CPU     Time: Total= %lg (Partial= %lg) s",
    120129          cpuSecT, cpuSecP);
    121   cout << out << endl;
     130  os << out << endl;
    122131
    123132  if (etmt<60) {
    124133    int_4 etmtms = elapSecT%1000;
    125     sprintf(out,"%02d.%03d ms", etmt, etmtms);
     134    sprintf(out,"%02d.%03d s", etmt, etmtms);
    126135  }
    127136  else
     
    130139  if (etm<60) {
    131140    int_4 etmms = elapSecT%1000;
    132     sprintf(outp,"%02d.%03d ms", etm, etmms);
     141    sprintf(outp,"%02d.%03d s", etm, etmms);
    133142  }
    134143  else
    135144    sprintf(outp,"%02d:%02d:%02d", etm/3600, (etm%3600)/60, etm%60);
    136145       
    137   cout << "Elapsed Time: Total=" << out << " (Partial= " << outp << ")" << endl;
     146  os << "Elapsed Time: Total=" << out << " (Partial= " << outp << ")" << endl;
    138147}
    139148
     149} // FIN namespace SOPHYA
  • trunk/SophyaLib/SysTools/ctimer.h

    r3579 r3636  
    11// This may look like C code, but it is really -*- C++ -*-
    22//
    3 // $Id: ctimer.h,v 1.6 2009-02-20 11:07:02 ansari Exp $
     3// $Id: ctimer.h,v 1.7 2009-05-26 20:24:24 ansari Exp $
    44//
    55
     
    1313#include <sys/time.h>
    1414#include <string>
     15#include <iostream>
    1516
    1617using namespace std;
     
    3536  // Si pas de parametre affiche le nom donne a la creation.
    3637  void Split(const char* comm=0, bool prfg=false);
     38
     39  //! store partial CPU and elapsed time (no print)
     40  void SplitQ();
    3741
    3842  // Sert a eviter que GNU ne pretende qu'on utilise pas l'objet...
     
    6771  inline double PartialCPUTime() { return  cpuSecP; }
    6872
     73//! Print the CPU and elapsed time on os (partial time corresponding to the last call to Split())
     74  ostream& Print(ostream& os) const ;
     75//! Print the CPU and elapsed time on cout
     76  inline ostream& Print() const { return Print(cout); }
     77
    6978private:
    7079  clock_t cpu0, cpuSplit;
     
    7685};
    7786
     87/*! operator << overloading - Calls SplitQ() and Print() */
     88inline ostream& operator << (ostream& s, Timer& tm)
     89  {  tm.SplitQ(); tm.Print(s);  return(s);  }
     90
    7891} // namespace SOPHYA
    7992
Note: See TracChangeset for help on using the changeset viewer.