1 /****************************************************************
2 Copyright (C) 1992, 1998 Lucent Technologies
3 All Rights Reserved
4 
5 Permission to use, copy, modify, and distribute this software and
6 its documentation for any purpose and without fee is hereby
7 granted, provided that the above copyright notice appear in all
8 copies and that both that the copyright notice and this
9 permission notice and warranty disclaimer appear in supporting
10 documentation, and that the name of Lucent or any of its entities
11 not be used in advertising or publicity pertaining to
12 distribution of the software without specific, written prior
13 permission.
14 
15 LUCENT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
16 INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS.
17 IN NO EVENT SHALL LUCENT OR ANY OF ITS ENTITIES BE LIABLE FOR ANY
18 SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER
20 IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
21 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
22 THIS SOFTWARE.
23 ****************************************************************/
24 
25 /* Many Unix systems have a getrusage() that returns time with */
26 /* a resolution of microseconds.  Compile with -DNO_RUSAGE to */
27 /* avoid using this routine. */
28 
29 #ifdef KR_headers
30 #define Void /*void*/
31 #else
32 #define Void void
33 #endif
34 #ifdef __cplusplus
35 extern "C" double xectim_(Void);
36 #endif
37 
38 #ifdef __STDC__
39 #define ASSUME_STDC
40 #endif
41 #ifdef _WIN32
42 #undef  NO_RUSAGE
43 #define NO_RUSAGE
44 #undef  ASSUME_STDC
45 #define ASSUME_STDC
46 #endif
47 
48 #ifndef NO_RUSAGE /*{{*/
49 #include <sys/time.h>
50 #include <sys/resource.h>
51 
52  double
xectim_(Void)53 xectim_(Void)
54 {
55 	struct rusage R;
56 	getrusage(RUSAGE_SELF, &R);
57 	return R.ru_utime.tv_sec + R.ru_stime.tv_sec
58 		+ 1e-6*(R.ru_utime.tv_usec + R.ru_stime.tv_usec);
59 	}
60 
61 #else /* }NO_RUSAGE{ */
62 
63 #if defined(ASSUME_STDC) && !defined(Clocks_to_seconds) /*{{*/
64 #include "time.h"
65 
66  double
xectim_(Void)67 xectim_(Void)
68 { return (double)clock() / CLOCKS_PER_SEC; }
69 
70 #else /*}defined(__STDC__) && !defined(Clocks_to_seconds){*/
71 #include "sys/types.h"
72 #include "sys/times.h"
73 #ifndef Clocks_to_seconds /*{*/
74 #ifdef CRAY /*{{*/
75 #define Clocks_to_seconds * 9.5e-9
76 #else /*}CRAY{*/
77 
78 #ifndef HZ /*{*/
79 #include "limits.h"
80 #ifdef CLOCKS_PER_SEC /*{{*/
81 #define HZ (double)(CLOCKS_PER_SEC)
82 #else /*}CLOCKS_PER_SEC{*/
83 #ifdef CLK_TCK /*{{*/
84 #define HZ (double)(CLK_TCK)
85 #else /*}CLK_TCK{*/
86 #ifdef mips /*{{*/
87 #define HZ 100.0
88 #else /*}mips{*/
89 #define HZ 60.0
90 #endif /*}}mips*/
91 #endif /*}}CLK_TCK*/
92 #endif /*}}CLOCKS_PER_SEC*/
93 #endif /*}HZ*/
94 #define Clocks_to_seconds / HZ
95 #endif /*}}CRAY*/
96 #endif /*}Clocks_to_seconds*/
97 
xectim_(Void)98 double xectim_(Void)
99 {
100 	struct tms t;
101 
102 	times(&t);
103 	return((t.tms_utime + t.tms_stime) Clocks_to_seconds);
104 	}
105 #endif /*}}defined(__STDC__) && !defined(Clocks_to_seconds)*/
106 #endif /*}}NO_RUSAGE*/
107