Geant4  v4-10.4-release
 모두 클래스 네임스페이스들 파일들 함수 변수 타입정의 열거형 타입 열거형 멤버 Friends 매크로 그룹들 페이지들
G4Timer.hh
이 파일의 문서화 페이지로 가기
1 //
2 // ********************************************************************
3 // * License and Disclaimer *
4 // * *
5 // * The Geant4 software is copyright of the Copyright Holders of *
6 // * the Geant4 Collaboration. It is provided under the terms and *
7 // * conditions of the Geant4 Software License, included in the file *
8 // * LICENSE and available at http://cern.ch/geant4/license . These *
9 // * include a list of copyright holders. *
10 // * *
11 // * Neither the authors of this software system, nor their employing *
12 // * institutes,nor the agencies providing financial support for this *
13 // * work make any representation or warranty, express or implied, *
14 // * regarding this software system or assume any liability for its *
15 // * use. Please see the license in the file LICENSE and URL above *
16 // * for the full disclaimer and the limitation of liability. *
17 // * *
18 // * This code implementation is the result of the scientific and *
19 // * technical work of the GEANT4 collaboration. *
20 // * By using, copying, modifying or distributing the software (or *
21 // * any work based on the software) you agree to acknowledge its *
22 // * use in resulting scientific publications, and indicate your *
23 // * acceptance of all terms of the Geant4 Software license. *
24 // ********************************************************************
25 //
26 //
27 // $Id: G4Timer.hh 110674 2018-06-07 10:30:11Z gcosmo $
28 //
29 //
30 // ----------------------------------------------------------------------
31 // Class G4Timer
32 //
33 // Class description:
34 //
35 // Class for timer objects, able to measure elasped user/system process time.
36 //
37 // Note: Uses <sys/times.h> & <unistd.h> - POSIX.1 defined
38 // If used, this header must be included in the source (.cc) file and it
39 // must be the first header file to be included!
40 //
41 // Member functions:
42 //
43 // G4Timer()
44 // Construct a timer object
45 // Start()
46 // Start timing
47 // Stop()
48 // Stop timing
49 // G4bool IsValid()
50 // Return true if have a valid time (ie start() and stop() called)
51 // G4double GetRealElapsed()
52 // Return the elapsed real time between last calling start() and stop()
53 // G4double GetSystemElapsed()
54 // Return the elapsed system time between last calling start() and stop()
55 // G4double GetUserElapsed()
56 // Return the elapsed user time between last calling start() and stop()
57 //
58 // Operators:
59 //
60 // std::ostream& operator << (std::ostream& os, const G4Timer& t);
61 // Print the elapsed real,system and usertimes on os. Prints **s for times
62 // if !IsValid
63 //
64 // Member data:
65 //
66 // G4bool fValidTimes
67 // True after start and stop have both been called more than once and
68 // an equal number of times
69 // clock_t fStartRealTime,fEndRealTime
70 // Real times (arbitrary time 0)
71 // tms fStartTimes,fEndTimes
72 // Timing structures (see times(2)) for start and end times
73 
74 // History:
75 // 23.08.96 P.Kent Updated to also computed real elapsed time
76 // 21.08.95 P.Kent
77 // 29.04.97 G.Cosmo Added timings for Windows/NT
78 
79 #ifndef G4TIMER_HH
80 #define G4TIMER_HH
81 
82 #ifndef WIN32
83 # include <unistd.h>
84 # include <sys/times.h>
85 #else
86 # include <time.h>
87 # define _SC_CLK_TCK 1
88 
89  extern "C" {
90  int sysconf(int);
91  };
92 
93  // Structure returned by times()
94 
95  struct tms {
96  clock_t tms_utime; /* user time */
97  clock_t tms_stime; /* system time */
98  clock_t tms_cutime; /* user time, children */
99  clock_t tms_cstime; /* system time, children */
100  };
101 
102  extern "C" {
103  extern clock_t times(struct tms *);
104  };
105 #endif /* WIN32 */
106 
107 #include "G4Types.hh"
108 #include "G4ios.hh"
109 
110 #include <chrono>
111 
112 class G4Timer
113 {
114  typedef std::chrono::high_resolution_clock clock_type;
115 
116 public:
117 
118  G4Timer();
119 
120  inline void Start();
121  inline void Stop();
122  inline G4bool IsValid() const;
123  inline const char* GetClockTime() const;
124  G4double GetRealElapsed() const;
125  G4double GetSystemElapsed() const;
126  G4double GetUserElapsed() const;
127 
128 private:
129 
131  std::chrono::time_point<clock_type> fStartRealTime, fEndRealTime;
133 };
134 
135 std::ostream& operator << (std::ostream& os, const G4Timer& t);
136 
137 #include "G4Timer.icc"
138 
139 #endif
G4double GetRealElapsed() const
Definition: G4Timer.cc:122
std::ostream & operator<<(std::ostream &, const BasicVector3D< float > &)
std::chrono::time_point< clock_type > fEndRealTime
Definition: G4Timer.hh:131
void Start()
const char * GetClockTime() const
std::chrono::high_resolution_clock clock_type
Definition: G4Timer.hh:114
G4Timer()
Definition: G4Timer.cc:117
double G4double
Definition: G4Types.hh:76
bool G4bool
Definition: G4Types.hh:79
G4double GetSystemElapsed() const
Definition: G4Timer.cc:134
void Stop()
G4double GetUserElapsed() const
Definition: G4Timer.cc:145
G4bool fValidTimes
Definition: G4Timer.hh:130
tms fStartTimes
Definition: G4Timer.hh:132
tms fEndTimes
Definition: G4Timer.hh:132
std::chrono::time_point< clock_type > fStartRealTime
Definition: G4Timer.hh:131
G4bool IsValid() const