File: time.hweb

package info (click to toggle)
fweb 1.60beta-11
  • links: PTS
  • area: main
  • in suites: hamm
  • size: 4,348 kB
  • ctags: 5,018
  • sloc: ansic: 38,347; makefile: 393; sh: 163
file content (76 lines) | stat: -rw-r--r-- 2,187 bytes parent folder | download
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
@z --- time.hweb ---

FWEB version 1.60-beta (January 1, 1997)

Based on version 0.5 of S. Levy's CWEB [copyright (C) 1987 Princeton University]

@x-----------------------------------------------------------------------------

@ This file is included into \.{includes.hweb}. It takes care of the
details of cpu and wall clock timing.

@<Operating sys...@>=

/* --- TIMING --- */

/* The compiler-line macro |timing_width| overrides the default format for
the time output; it's the number of \.x's in \.{n.xx} seconds. (See
\.{custom.web}.) */ 
#ifndef TIMING_WIDTH
	#define TIMING_WIDTH 1 // We ensure that it's defined to something.
#endif /* |TIMING_WIDTH| */

#include <time.h> /* ANSI: Time-conversion routines. (For non-ANSI
			machines, defines |struct tm|.) */

#if TIMING

/* We like wall-clock timing more precise than seconds. */

 /* \.{Machine-dependent}: Non-ANSI timing: */
#if HAVE_GETTIMEOFDAY
	/* uSec timing */
	#include <sys/time.h>
	#undef NEW_DIFFTIME
	#define NEW_DIFFTIME 1
	#define TIME_T struct timeval
	#ifdef _COMMON_h
		struct timezone tz_dummy;
	#endif
	int gettimeofday PROTO((struct timeval *tp, struct timezone *tzp));
	#define TIME(p) gettimeofday(p, &tz_dummy)
#else
#if HAVE_SYS_TIMEB_H
	/* mSec timing */
	#include <sys/timeb.h>
	#undef NEW_DIFFTIME
	#define NEW_DIFFTIME 1
	#define TIME_T struct timeb 
	#define TIME(p) ftime(p)
#else /* ANSI timing */
	#define TIME_T time_t
	#define TIME(p) time(p)
#endif // |HAVE_SYS_TIMEB_H|
#endif // |HAVE_GETTIMEOFDAY|

#if NEW_DIFFTIME
	#define DIFFTIME diff_time /* We supply our own version of
|difftime| when we don't like the ANSI version. See \.{common.web}. (We
can't just call our new version |difftime| because if that's already been
prototyped the compiler will complain about a prototype mismatch.) */
#else
	#define DIFFTIME difftime /* Use the ANSI routine. */
#endif // |NEW_DIFFTIME|

clock_t clock PROTO((VOID)); // Not defined on some machines.

#ifndef CLOCKS_PER_SEC
	#ifdef CLK_TCK
		#define CLOCKS_PER_SEC CLK_TCK // Some use older name.
	#else
		#define CLOCKS_PER_SEC 1000000 /* Guess at default:
$\mu$sec timing. */ 
	#endif // |CLK_TCK|
#endif // |CLOCKS_PER_SEC|

#endif // |TIMING|