emergency commit
[cl-cudd.git] / distr / util / cpu_time.c
blob2a4be924053e54dc04cdd083a38b64cbe925db99
1 /* LINTLIBRARY */
3 #include <stdio.h>
4 #include "util.h"
6 #ifdef IBM_WATC /* IBM Waterloo-C compiler (same as bsd 4.2) */
7 #define void int
8 #define BSD
9 #endif
11 #ifdef BSD
12 #include <sys/types.h>
13 #include <sys/time.h>
14 #include <sys/resource.h>
15 #endif
17 #if defined(UNIX60) || defined(UNIX100) || defined(__CYGWIN32__)
18 #include <sys/types.h>
19 #include <sys/times.h>
20 #endif
22 #ifdef vms /* VAX/C compiler -- times() with 100 HZ clock */
23 #include <types.h>
24 #include <time.h>
25 #endif
30 * util_cpu_time -- return a long which represents the elapsed processor
31 * time in milliseconds since some constant reference
33 long
34 util_cpu_time()
36 long t = 0;
38 #ifdef BSD
39 struct rusage rusage;
40 (void) getrusage(RUSAGE_SELF, &rusage);
41 t = (long) rusage.ru_utime.tv_sec*1000 + rusage.ru_utime.tv_usec/1000;
42 #endif
44 #ifdef IBMPC
45 long ltime;
46 (void) time(&ltime);
47 t = ltime * 1000;
48 #endif
50 #ifdef UNIX60 /* times() with 60 Hz resolution */
51 struct tms buffer;
52 times(&buffer);
53 t = buffer.tms_utime * 16.6667;
54 #endif
56 #ifdef UNIX100
57 struct tms buffer; /* times() with 100 Hz resolution */
58 times(&buffer);
59 t = buffer.tms_utime * 10;
60 #endif
62 #ifdef __CYGWIN32__
63 /* Works under Windows NT but not Windows 95. */
64 struct tms buffer; /* times() with 1000 Hz resolution */
65 times(&buffer);
66 t = buffer.tms_utime;
67 #endif
69 #ifdef vms
70 tbuffer_t buffer; /* times() with 100 Hz resolution */
71 times(&buffer);
72 t = buffer.proc_user_time * 10;
73 #endif
75 return t;