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