26 |
single way is available for all host systems, nor are there reliable |
single way is available for all host systems, nor are there reliable |
27 |
ways to find out which way is correct for a given host. */ |
ways to find out which way is correct for a given host. */ |
28 |
|
|
29 |
#include <time.h> |
#ifdef TIME_WITH_SYS_TIME |
30 |
|
# include <sys/time.h> |
31 |
|
# include <time.h> |
32 |
|
#else |
33 |
|
# if HAVE_SYS_TIME_H |
34 |
|
# include <sys/time.h> |
35 |
|
# else |
36 |
|
# ifdef HAVE_TIME_H |
37 |
|
# include <time.h> |
38 |
|
# endif |
39 |
|
# endif |
40 |
|
#endif |
41 |
|
|
42 |
#if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H) |
#if defined (HAVE_GETRUSAGE) && defined (HAVE_SYS_RESOURCE_H) |
|
#include <sys/time.h> |
|
43 |
#include <sys/resource.h> |
#include <sys/resource.h> |
44 |
#endif |
#endif |
45 |
|
|
50 |
#include <sys/times.h> |
#include <sys/times.h> |
51 |
#endif |
#endif |
52 |
|
|
53 |
|
#ifdef HAVE_UNISTD_H |
54 |
|
#include <unistd.h> |
55 |
|
#endif |
56 |
|
|
57 |
/* This is a fallback; if wrong, it will likely make obviously wrong |
/* This is a fallback; if wrong, it will likely make obviously wrong |
58 |
results. */ |
results. */ |
59 |
|
|
61 |
#define CLOCKS_PER_SEC 1 |
#define CLOCKS_PER_SEC 1 |
62 |
#endif |
#endif |
63 |
|
|
64 |
#if defined (HAVE_TIMES) && ! defined (HZ) |
#ifdef _SC_CLK_TCK |
65 |
#define HZ CLOCKS_PER_SEC |
#define GNU_HZ sysconf(_SC_CLK_TCK) |
66 |
|
#else |
67 |
|
#ifdef HZ |
68 |
|
#define GNU_HZ HZ |
69 |
|
#else |
70 |
|
#ifdef CLOCKS_PER_SEC |
71 |
|
#define GNU_HZ CLOCKS_PER_SEC |
72 |
|
#endif |
73 |
|
#endif |
74 |
#endif |
#endif |
75 |
|
|
76 |
long |
long |
87 |
struct tms tms; |
struct tms tms; |
88 |
|
|
89 |
times (&tms); |
times (&tms); |
90 |
return (tms.tms_utime + tms.tms_stime) * (1000000 / HZ); |
return (tms.tms_utime + tms.tms_stime) * (1000000 / GNU_HZ); |
91 |
#else /* ! HAVE_TIMES */ |
#else /* ! HAVE_TIMES */ |
92 |
/* Fall back on clock and hope it's correctly implemented. */ |
/* Fall back on clock and hope it's correctly implemented. */ |
93 |
const long clocks_per_sec = CLOCKS_PER_SEC; |
const long clocks_per_sec = CLOCKS_PER_SEC; |