1CLOCK(P) POSIX Programmer's Manual CLOCK(P)
2
3
4
6 clock - report CPU time used
7
9 #include <time.h>
10
11 clock_t clock(void);
12
13
15 The clock() function shall return the implementation's best approxima‐
16 tion to the processor time used by the process since the beginning of
17 an implementation-defined era related only to the process invocation.
18
20 To determine the time in seconds, the value returned by clock() should
21 be divided by the value of the macro CLOCKS_PER_SEC. CLOCKS_PER_SEC
22 is defined to be one million in <time.h>. If the processor time used
23 is not available or its value cannot be represented, the function shall
24 return the value ( clock_t)-1.
25
27 No errors are defined.
28
29 The following sections are informative.
30
32 None.
33
35 In order to measure the time spent in a program, clock() should be
36 called at the start of the program and its return value subtracted from
37 the value returned by subsequent calls. The value returned by clock()
38 is defined for compatibility across systems that have clocks with dif‐
39 ferent resolutions. The resolution on any particular system need not be
40 to microsecond accuracy.
41
42 The value returned by clock() may wrap around on some implementations.
43 For example, on a machine with 32-bit values for clock_t, it wraps
44 after 2147 seconds or 36 minutes.
45
47 None.
48
50 None.
51
53 asctime() , ctime() , difftime() , gmtime() , localtime() , mktime() ,
54 strftime() , strptime() , time() , utime() , the Base Definitions vol‐
55 ume of IEEE Std 1003.1-2001, <time.h>
56
58 Portions of this text are reprinted and reproduced in electronic form
59 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
60 -- Portable Operating System Interface (POSIX), The Open Group Base
61 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
62 Electrical and Electronics Engineers, Inc and The Open Group. In the
63 event of any discrepancy between this version and the original IEEE and
64 The Open Group Standard, the original IEEE and The Open Group Standard
65 is the referee document. The original Standard can be obtained online
66 at http://www.opengroup.org/unix/online.html .
67
68
69
70IEEE/The Open Group 2003 CLOCK(P)