1 |
/* ASCEND modelling environment |
2 |
Copyright (C) 1997 Carnegie Mellon University |
3 |
Copyright (C) 2015 John Pye |
4 |
|
5 |
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 |
#include "platform.h" |
24 |
#include "panic.h" |
25 |
#include "tm_time.h" |
26 |
|
27 |
#ifdef __WIN32__ |
28 |
# include "Windows.h" |
29 |
#endif |
30 |
|
31 |
static boolean f_first = TRUE; |
32 |
|
33 |
double tm_cpu_time(void){ |
34 |
#ifndef __WIN32__ |
35 |
static struct timespec ref; |
36 |
struct timespec now; |
37 |
|
38 |
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 |
#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 |
} |
56 |
|
57 |
double tm_reset_cpu_time(void) |
58 |
{ |
59 |
f_first = TRUE; |
60 |
return tm_cpu_time(); |
61 |
} |
62 |
|
63 |
void tm_cpu_time_ftn_(double *t) |
64 |
{ |
65 |
asc_assert(NULL != t); |
66 |
*t = tm_cpu_time(); |
67 |
} |
68 |
|
69 |
void aftime_(double *t) |
70 |
{ |
71 |
asc_assert(NULL != t); |
72 |
*t = tm_cpu_time(); |
73 |
} |
74 |
|
75 |
void tm_cpu_time_ftn(double *t) |
76 |
{ |
77 |
asc_assert(NULL != t); |
78 |
*t = tm_cpu_time(); |
79 |
} |
80 |
|
81 |
void aftime(double *t) |
82 |
{ |
83 |
asc_assert(NULL != t); |
84 |
*t = tm_cpu_time(); |
85 |
} |
86 |
|
87 |
void TM_CPU_TIME_FTN(double *t) |
88 |
{ |
89 |
asc_assert(NULL != t); |
90 |
*t = tm_cpu_time(); |
91 |
} |
92 |
|
93 |
void AFTIME(double *t) |
94 |
{ |
95 |
asc_assert(NULL != t); |
96 |
*t = tm_cpu_time(); |
97 |
} |