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