StRoot  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
StTimer.cc
1 /***************************************************************************
2  *
3  * $Id: StTimer.cc,v 1.1 1999/04/27 19:23:44 ullrich Exp $
4  *
5  * Author: Thomas Ullrich, April 1999
6  ***************************************************************************
7  *
8  * Description: CPU timer
9  *
10  ***************************************************************************
11  *
12  * $Log: StTimer.cc,v $
13  * Revision 1.1 1999/04/27 19:23:44 ullrich
14  * Initial Revision
15  *
16  **************************************************************************/
17 #include <time.h>
18 #include <stdlib.h>
19 #include "StTimer.hh"
20 
21 StTimer::StTimer() : mStartTime(0), mStopTime(0), mIsStopped(1)
22 {/* noop */}
23 
24 double StTimer::resolution() const
25 {
26  return 1./double(CLOCKS_PER_SEC);
27 }
28 
29 double StTimer::elapsedTime() const
30 {
31  return (mIsStopped ? mStopTime : absoluteTime()) - mStartTime;
32 }
33 
34 void StTimer::reset()
35 {
36  mStartTime = 0;
37  mStopTime = 0;
38  mIsStopped = 1;
39 }
40 
41 void StTimer::start()
42 {
43  mStartTime = absoluteTime() - elapsedTime();
44  mIsStopped = 0;
45 }
46 
47 void StTimer::stop()
48 {
49  mStopTime = absoluteTime();
50  mIsStopped = 1;
51 }
52 
53 
54 double StTimer::absoluteTime()
55 {
56  return (double)clock()/CLOCKS_PER_SEC;
57 }
58