Re: [ROOT] TStopwatch doesn't reset

From: Valery Fine (fine@bnl.gov)
Date: Sun Jan 07 2001 - 02:12:57 MET


Hello Dave

> I'm not sure if this is a Windows-specific feature of Root or not, but I
> cannot get TStopwatch to reset.
 
> Neither the reset argument to the Start method nor the explicit ResetCpuTime
> method cause the counter to reset.
 
> Also it appears to be an undocumented (and probably unintended) feature that
> all TStopwatch objects return the same values.

Did you pay your attention both methods as GetCPUTime as GetRealTime are declared 
as "static". This means they are not linked with any particular object and Must return
one and the same value with any TStopwatch pointer provided as well as with no pointer 
at all.  It is not a feature of this class it is a nature of "static" methods in C++.

GetCPUTime tells how much processor time the calling process has used. 
One needs no TStopwatch object to be able to call this method.

>  For instance, in the following code fragment, both timers return identical values 
> (which are proportional to the number of iterations in the for loop):

Yes, this Ok (see above)

I.e. you can change your code as follows to get the same result:


 TStopwatch timer1;
 timer1.Start(kTRUE);
 for (Int_t i=0; i<1000000; i++) {}
 timer1.Stop();
 Double_t t1 = TStopwatch::GetCPUTime();
 TStopwatch timer2;
 timer2.Start(kTRUE);
 timer2.Stop();
 Double_t t2 = TStopwatch::GetCPUTime();
 std::cout << t1 << " " << t2 << std::endl;
 

To get what you want you should use CPUtime and RealTime methods.
They are documented.

http://root.cern.ch/root/htmldoc/TStopwatch.html#TStopwatch:CpuTime


http://root.cern.ch/root/htmldoc/TStopwatch.html#TStopwatch:RealTime

  Hope this helps.  
  With my best regards,
                            Valeri



This archive was generated by hypermail 2b29 : Tue Jan 01 2002 - 17:50:33 MET