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
20 The functionality described on this reference page is aligned with the
21 ISO C standard. Any conflict between the requirements described here
22 and the ISO C standard is unintentional. This volume of POSIX.1‐2017
23 defers to the ISO C standard.
24
25 The clock() function shall return the implementation's best approxima‐
26 tion to the processor time used by the process since the beginning of
27 an implementation-defined era related only to the process invocation.
28
30 To determine the time in seconds, the value returned by clock() should
31 be divided by the value of the macro CLOCKS_PER_SEC. CLOCKS_PER_SEC is
32 defined to be one million in <time.h>. If the processor time used is
33 not available or its value cannot be represented, the function shall
34 return the value (clock_t)-1.
35
37 No errors are defined.
38
39 The following sections are informative.
40
42 None.
43
45 In programming environments where clock_t is a 32-bit integer type and
46 CLOCKS_PER_SEC is one million, clock() will start failing in less than
47 36 minutes of processor time for signed clock_t, or 72 minutes for
48 unsigned clock_t. Applications intended to be portable to such envi‐
49 ronments should use times() instead (or clock_gettime() with
50 CLOCK_PROCESS_CPUTIME_ID, if supported).
51
52 In order to measure the time spent in a program, clock() should be
53 called at the start of the program and its return value subtracted from
54 the value returned by subsequent calls. The value returned by clock()
55 is defined for compatibility across systems that have clocks with dif‐
56 ferent resolutions. The resolution on any particular system need not be
57 to microsecond accuracy.
58
60 None.
61
63 None.
64
66 asctime(), clock_getres(), ctime(), difftime(), gmtime(), localtime(),
67 mktime(), strftime(), strptime(), time(), times(), utime()
68
69 The Base Definitions volume of POSIX.1‐2017, <time.h>
70
72 Portions of this text are reprinted and reproduced in electronic form
73 from IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
74 table Operating System Interface (POSIX), The Open Group Base Specifi‐
75 cations Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of
76 Electrical and Electronics Engineers, Inc and The Open Group. In the
77 event of any discrepancy between this version and the original IEEE and
78 The Open Group Standard, the original IEEE and The Open Group Standard
79 is the referee document. The original Standard can be obtained online
80 at http://www.opengroup.org/unix/online.html .
81
82 Any typographical or formatting errors that appear in this page are
83 most likely to have been introduced during the conversion of the source
84 files to man page format. To report such errors, see https://www.ker‐
85 nel.org/doc/man-pages/reporting_bugs.html .
86
87
88
89IEEE/The Open Group 2017 CLOCK(3P)