1clock(3) Library Functions Manual clock(3)
2
3
4
6 clock - determine processor time
7
9 Standard C library (libc, -lc)
10
12 #include <time.h>
13
14 clock_t clock(void);
15
17 The clock() function returns an approximation of processor time used by
18 the program.
19
21 The value returned is the CPU time used so far as a clock_t; to get the
22 number of seconds used, divide by CLOCKS_PER_SEC. If the processor
23 time used is not available or its value cannot be represented, the
24 function returns the value (clock_t) -1.
25
27 For an explanation of the terms used in this section, see at‐
28 tributes(7).
29
30 ┌────────────────────────────────────────────┬───────────────┬─────────┐
31 │Interface │ Attribute │ Value │
32 ├────────────────────────────────────────────┼───────────────┼─────────┤
33 │clock() │ Thread safety │ MT-Safe │
34 └────────────────────────────────────────────┴───────────────┴─────────┘
35
37 XSI requires that CLOCKS_PER_SEC equals 1000000 independent of the ac‐
38 tual resolution.
39
40 On several other implementations, the value returned by clock() also
41 includes the times of any children whose status has been collected via
42 wait(2) (or another wait-type call). Linux does not include the times
43 of waited-for children in the value returned by clock(). The times(2)
44 function, which explicitly returns (separate) information about the
45 caller and its children, may be preferable.
46
48 C11, POSIX.1-2008.
49
51 POSIX.1-2001, C89.
52
53 In glibc 2.17 and earlier, clock() was implemented on top of times(2).
54 For improved accuracy, since glibc 2.18, it is implemented on top of
55 clock_gettime(2) (using the CLOCK_PROCESS_CPUTIME_ID clock).
56
58 The C standard allows for arbitrary values at the start of the program;
59 subtract the value returned from a call to clock() at the start of the
60 program to get maximum portability.
61
62 Note that the time can wrap around. On a 32-bit system where
63 CLOCKS_PER_SEC equals 1000000 this function will return the same value
64 approximately every 72 minutes.
65
67 clock_gettime(2), getrusage(2), times(2)
68
69
70
71Linux man-pages 6.04 2023-03-30 clock(3)