14 #if (MFEM_TIMER_TYPE == 0)
16 #elif (MFEM_TIMER_TYPE == 1)
17 #include <sys/times.h>
20 #elif (MFEM_TIMER_TYPE == 2)
22 #if (!defined(CLOCK_MONOTONIC) || !defined(CLOCK_PROCESS_CPUTIME_ID))
23 #error "CLOCK_MONOTONIC and CLOCK_PROCESS_CPUTIME_ID not defined in <time.h>"
25 #elif (MFEM_TIMER_TYPE == 3)
30 #error "Unknown MFEM_TIMER_TYPE"
42 #if (MFEM_TIMER_TYPE == 0)
43 std::clock_t user_time, start_utime;
44 #elif (MFEM_TIMER_TYPE == 1)
45 clock_t real_time, user_time, syst_time;
46 clock_t start_rtime, start_utime, start_stime;
48 inline void Current(clock_t *, clock_t *, clock_t *);
49 #elif (MFEM_TIMER_TYPE == 2)
50 struct timespec real_time, user_time;
51 struct timespec start_rtime, start_utime;
52 inline void GetRealTime(
struct timespec &tp);
53 inline void GetUserTime(
struct timespec &tp);
54 #elif (MFEM_TIMER_TYPE == 3)
55 LARGE_INTEGER frequency, real_time, start_rtime;
64 inline double Resolution();
65 inline double RealTime();
66 inline double UserTime();
67 inline double SystTime();
72 #if (MFEM_TIMER_TYPE == 0)
74 #elif (MFEM_TIMER_TYPE == 1)
75 my_CLK_TCK = sysconf(_SC_CLK_TCK);
76 real_time = user_time = syst_time = 0;
77 #elif (MFEM_TIMER_TYPE == 2)
78 real_time.tv_sec = user_time.tv_sec = 0;
79 real_time.tv_nsec = user_time.tv_nsec = 0;
80 #elif (MFEM_TIMER_TYPE == 3)
81 QueryPerformanceFrequency(&frequency);
82 real_time.QuadPart = 0;
87 #if (MFEM_TIMER_TYPE == 1)
88 inline void StopWatch::Current(clock_t *r, clock_t *u, clock_t *s)
93 *u = my_tms.tms_utime;
94 *s = my_tms.tms_stime;
96 #elif (MFEM_TIMER_TYPE == 2)
97 inline void StopWatch::GetRealTime(
struct timespec &tp)
99 clock_gettime(CLOCK_MONOTONIC, &tp);
102 inline void StopWatch::GetUserTime(
struct timespec &tp)
104 clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &tp);
110 #if (MFEM_TIMER_TYPE == 0)
114 start_utime = std::clock();
116 #elif (MFEM_TIMER_TYPE == 1)
117 real_time = user_time = syst_time = 0;
120 Current(&start_rtime, &start_utime, &start_stime);
122 #elif (MFEM_TIMER_TYPE == 2)
123 real_time.tv_sec = user_time.tv_sec = 0;
124 real_time.tv_nsec = user_time.tv_nsec = 0;
127 GetRealTime(start_rtime);
128 GetUserTime(start_utime);
130 #elif (MFEM_TIMER_TYPE == 3)
131 real_time.QuadPart = 0;
134 QueryPerformanceCounter(&start_rtime);
141 if (Running) {
return; }
142 #if (MFEM_TIMER_TYPE == 0)
143 start_utime = std::clock();
144 #elif (MFEM_TIMER_TYPE == 1)
145 Current(&start_rtime, &start_utime, &start_stime);
146 #elif (MFEM_TIMER_TYPE == 2)
147 GetRealTime(start_rtime);
148 GetUserTime(start_utime);
149 #elif (MFEM_TIMER_TYPE == 3)
150 QueryPerformanceCounter(&start_rtime);
157 if (!Running) {
return; }
158 #if (MFEM_TIMER_TYPE == 0)
159 user_time += ( std::clock() - start_utime );
160 #elif (MFEM_TIMER_TYPE == 1)
161 clock_t curr_rtime, curr_utime, curr_stime;
162 Current(&curr_rtime, &curr_utime, &curr_stime);
163 real_time += ( curr_rtime - start_rtime );
164 user_time += ( curr_utime - start_utime );
165 syst_time += ( curr_stime - start_stime );
166 #elif (MFEM_TIMER_TYPE == 2)
167 struct timespec curr_rtime, curr_utime;
168 GetRealTime(curr_rtime);
169 GetUserTime(curr_utime);
170 real_time.tv_sec += ( curr_rtime.tv_sec - start_rtime.tv_sec );
171 real_time.tv_nsec += ( curr_rtime.tv_nsec - start_rtime.tv_nsec );
172 user_time.tv_sec += ( curr_utime.tv_sec - start_utime.tv_sec );
173 user_time.tv_nsec += ( curr_utime.tv_nsec - start_utime.tv_nsec );
174 #elif (MFEM_TIMER_TYPE == 3)
175 LARGE_INTEGER curr_rtime;
176 QueryPerformanceCounter(&curr_rtime);
177 real_time.QuadPart += (curr_rtime.QuadPart - start_rtime.QuadPart);
184 #if (MFEM_TIMER_TYPE == 0)
185 return 1.0 / CLOCKS_PER_SEC;
186 #elif (MFEM_TIMER_TYPE == 1)
187 return 1.0 / my_CLK_TCK;
188 #elif (MFEM_TIMER_TYPE == 2)
193 clock_getres(CLOCK_MONOTONIC, &res);
194 return res.tv_sec + 1e-9*res.tv_nsec;
195 #elif (MFEM_TIMER_TYPE == 3)
196 return 1.0 / frequency.QuadPart;
202 #if (MFEM_TIMER_TYPE == 0)
204 #elif (MFEM_TIMER_TYPE == 1)
205 clock_t curr_rtime, curr_utime, curr_stime;
206 clock_t rtime = real_time;
209 Current(&curr_rtime, &curr_utime, &curr_stime);
210 rtime += (curr_rtime - start_rtime);
212 return (
double)(rtime) / my_CLK_TCK;
213 #elif (MFEM_TIMER_TYPE == 2)
216 struct timespec curr_rtime;
217 GetRealTime(curr_rtime);
218 return ((real_time.tv_sec + (curr_rtime.tv_sec - start_rtime.tv_sec)) +
219 1e-9*(real_time.tv_nsec +
220 (curr_rtime.tv_nsec - start_rtime.tv_nsec)));
224 return real_time.tv_sec + 1e-9*real_time.tv_nsec;
226 #elif (MFEM_TIMER_TYPE == 3)
227 LARGE_INTEGER curr_rtime, rtime = real_time;
230 QueryPerformanceCounter(&curr_rtime);
231 rtime.QuadPart += (curr_rtime.QuadPart - start_rtime.QuadPart);
233 return (
double)(rtime.QuadPart) / frequency.QuadPart;
239 #if (MFEM_TIMER_TYPE == 0)
240 std::clock_t utime = user_time;
243 utime += (std::clock() - start_utime);
245 return (
double)(utime) / CLOCKS_PER_SEC;
246 #elif (MFEM_TIMER_TYPE == 1)
247 clock_t curr_rtime, curr_utime, curr_stime;
248 clock_t utime = user_time;
251 Current(&curr_rtime, &curr_utime, &curr_stime);
252 utime += (curr_utime - start_utime);
254 return (
double)(utime) / my_CLK_TCK;
255 #elif (MFEM_TIMER_TYPE == 2)
258 struct timespec curr_utime;
259 GetUserTime(curr_utime);
260 return ((user_time.tv_sec + (curr_utime.tv_sec - start_utime.tv_sec)) +
261 1e-9*(user_time.tv_nsec +
262 (curr_utime.tv_nsec - start_utime.tv_nsec)));
266 return user_time.tv_sec + 1e-9*user_time.tv_nsec;
268 #elif (MFEM_TIMER_TYPE == 3)
275 #if (MFEM_TIMER_TYPE == 1)
276 clock_t curr_rtime, curr_utime, curr_stime;
277 clock_t stime = syst_time;
280 Current(&curr_rtime, &curr_utime, &curr_stime);
281 stime += (curr_stime - start_stime);
283 return (
double)(stime) / my_CLK_TCK;
294 M =
new internal::StopWatch;
314 return M->Resolution();
319 return M->RealTime();
324 return M->UserTime();
329 return M->SystTime();