1 |
jpye |
2846 |
/* ASCEND modelling environment |
2 |
|
|
Copyright (C) 1997 Carnegie Mellon University |
3 |
|
|
Copyright (C) 2015 John Pye |
4 |
aw0a |
1 |
|
5 |
jpye |
2846 |
This program is free software; you can redistribute it and/or modify |
6 |
|
|
it under the terms of the GNU General Public License as published by |
7 |
|
|
the Free Software Foundation; either version 2, or (at your option) |
8 |
|
|
any later version. |
9 |
|
|
|
10 |
|
|
This program is distributed in the hope that it will be useful, |
11 |
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 |
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 |
|
|
GNU General Public License for more details. |
14 |
|
|
|
15 |
|
|
You should have received a copy of the GNU General Public License |
16 |
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 |
|
|
*//* |
18 |
|
|
Time module by Karl Westerberg, created: 6/1990 |
19 |
|
|
Last in CVS: $Date: 2000/01/25 02:21:26 $ $Author: ballan $ |
20 |
|
|
*/ |
21 |
|
|
|
22 |
|
|
#include <sys/time.h> |
23 |
jpye |
2323 |
#include "platform.h" |
24 |
|
|
#include "panic.h" |
25 |
johnpye |
399 |
#include "tm_time.h" |
26 |
aw0a |
1 |
|
27 |
jpye |
2904 |
#ifdef __WIN32__ |
28 |
|
|
# include "Windows.h" |
29 |
|
|
#endif |
30 |
|
|
|
31 |
jds |
59 |
static boolean f_first = TRUE; |
32 |
|
|
|
33 |
jpye |
2846 |
double tm_cpu_time(void){ |
34 |
jpye |
2904 |
#ifndef __WIN32__ |
35 |
jpye |
2846 |
static struct timespec ref; |
36 |
|
|
struct timespec now; |
37 |
aw0a |
1 |
|
38 |
jpye |
2846 |
if( f_first ) { |
39 |
|
|
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &ref); |
40 |
|
|
f_first = FALSE; |
41 |
|
|
} |
42 |
|
|
clock_gettime(CLOCK_PROCESS_CPUTIME_ID, &now); |
43 |
|
|
return (now.tv_sec - ref.tv_sec) + 1e-9*(now.tv_nsec - ref.tv_nsec); |
44 |
jpye |
2904 |
#else /* WIN32 */ |
45 |
|
|
LARGE_INTEGER n1, f; |
46 |
|
|
LARGE_INTEGER n2; |
47 |
|
|
if(f_first){ |
48 |
|
|
QueryPerformanceFrequency(&f); |
49 |
|
|
QueryPerformanceCounter(&n1); |
50 |
|
|
return 0; |
51 |
|
|
} |
52 |
|
|
QueryPerformanceCounter(&n2); |
53 |
|
|
return((n2.QuadPart - n1.QuadPart)/f.QuadPart); |
54 |
|
|
#endif |
55 |
aw0a |
1 |
} |
56 |
|
|
|
57 |
jds |
59 |
double tm_reset_cpu_time(void) |
58 |
|
|
{ |
59 |
|
|
f_first = TRUE; |
60 |
|
|
return tm_cpu_time(); |
61 |
|
|
} |
62 |
|
|
|
63 |
aw0a |
1 |
void tm_cpu_time_ftn_(double *t) |
64 |
|
|
{ |
65 |
jds |
59 |
asc_assert(NULL != t); |
66 |
aw0a |
1 |
*t = tm_cpu_time(); |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
void aftime_(double *t) |
70 |
|
|
{ |
71 |
jds |
59 |
asc_assert(NULL != t); |
72 |
aw0a |
1 |
*t = tm_cpu_time(); |
73 |
|
|
} |
74 |
|
|
|
75 |
|
|
void tm_cpu_time_ftn(double *t) |
76 |
|
|
{ |
77 |
jds |
59 |
asc_assert(NULL != t); |
78 |
aw0a |
1 |
*t = tm_cpu_time(); |
79 |
|
|
} |
80 |
|
|
|
81 |
|
|
void aftime(double *t) |
82 |
|
|
{ |
83 |
jds |
59 |
asc_assert(NULL != t); |
84 |
aw0a |
1 |
*t = tm_cpu_time(); |
85 |
|
|
} |
86 |
|
|
|
87 |
|
|
void TM_CPU_TIME_FTN(double *t) |
88 |
|
|
{ |
89 |
jds |
59 |
asc_assert(NULL != t); |
90 |
aw0a |
1 |
*t = tm_cpu_time(); |
91 |
|
|
} |
92 |
|
|
|
93 |
|
|
void AFTIME(double *t) |
94 |
|
|
{ |
95 |
jds |
59 |
asc_assert(NULL != t); |
96 |
aw0a |
1 |
*t = tm_cpu_time(); |
97 |
|
|
} |