root / synthbench / euroben-ports / base / C / mod2am / cclock.c @ 0:839f52ef7657
History | View | Annotate | Download (1.1 kB)
1 |
#include <stdlib.h> |
---|---|
2 |
#include <sys/types.h> |
3 |
#include <sys/time.h> |
4 |
|
5 |
/* -------------------------------------------------------------------
|
6 |
|
7 |
This function returns the wall clock time with micro seconds
|
8 |
accuracy.
|
9 |
The data type of the returned value is "double".
|
10 |
|
11 |
The function can be called from a FORTRAN module. The value
|
12 |
returned by cclock_ and cclock should be of type REAL(Kind = 8).
|
13 |
|
14 |
-------------------------------------------------------------------
|
15 |
*/
|
16 |
|
17 |
double cclock_( void ) |
18 |
{ |
19 |
const double micro = 1.0e-06; /* Conversion constant */ |
20 |
static long start = 0L, startu; |
21 |
struct timeval tp; /* Structure used by gettimeofday */ |
22 |
double wall_time; /* To hold the result */ |
23 |
|
24 |
|
25 |
if ( gettimeofday( &tp, NULL) == -1 ) |
26 |
wall_time = -1.0e0; |
27 |
else if( !start ) { |
28 |
start = tp.tv_sec; |
29 |
startu = tp.tv_usec; |
30 |
wall_time = 0.0e0; |
31 |
} |
32 |
else
|
33 |
wall_time = (double) (tp.tv_sec - start) + micro*(tp.tv_usec - startu);
|
34 |
|
35 |
return wall_time;
|
36 |
} |
37 |
|
38 |
|
39 |
double cclock( void ) |
40 |
{ |
41 |
return cclock_();
|
42 |
} |