clock(3)
โจ clock(3) โจ
okay bestie, so this is the manual page for clock(3) from the Library Functions Manual, and it's genuinely SO much shorter than it looks, you're gonna eat this up ๐
๐ธ NAME ๐ธ
clock โ determine processor time
like, it tells you how much CPU time your program has munched. that's it. that's the whole gig โจ
๐ LIBRARY ๐
Standard C library (libc, -lc)
she lives in libc, no cap ๐ซถ
๐ SYNOPSIS ๐
#include <time.h>
clock_t clock(void);
no arguments, no drama, she takes nothing and returns a clock_t. iconic behavior honestly ๐
๐ DESCRIPTION ๐
The clock() function returns an approximation of processor time used by the program.
okay so real talk: it's an approximation, not gospel. it's giving "here's roughly how much CPU juice you've used" โจ
๐ฅ RETURN VALUE ๐ฅ
The value returned is the CPU time used so far as a clock_t; to get the number of seconds used, divide by CLOCKS_PER_SEC.
so like โ you get a clock_t back, and if you want actual seconds out of it you gotta do the math:
seconds = clock() / CLOCKS_PER_SEC;
If the processor time used is not available or its value cannot be represented, the function returns the value (clock_t) -1.
heads up bestie โ ๏ธ if the processor time isn't available, or the value literally can't be represented, you get (clock_t) -1 back. that's the "idk girl" return value. check for it, okay? don't just blindly divide ๐
๐ ATTRIBUTES ๐
For an explanation of the terms used in this section, see attributes(7).
clock()โ Attribute: Thread safety โ Value:MT-Safe
translation: she's MT-Safe, so multiple threads can call her without things getting messy ๐ง thread-safe queen, periodt.
๐ฆ VERSIONS ๐ฆ
XSI requires that CLOCKS_PER_SEC equals 1000000 independent of the actual resolution.
that's the XSI requirement, and don't forget it's 1000000 no matter what the actual resolution is doing ๐
On several other implementations, the value returned by clock() also includes the times of any children whose status has been collected via wait(2) (or another wait-type call). Linux does not include the times of waited-for children in the value returned by clock(). The times(2) function, which explicitly returns (separate) information about the caller and its children, may be preferable.
so on several other implementations, clock() is a little extra and lumps in the times of any children whose status got collected via wait(2) (or any other wait-type call). Linux does NOT do that โ waited-for children's times are not included in what clock() gives you on Linux, fr fr. so if you actually want that info, times(2) is the one to call, because she explicitly returns (separate) info about the caller and its children. Linux girlies, times(2) may be preferable ๐ซถ
๐ STANDARDS ๐
C11, POSIX.1-2008.
certified, standardized, slaying ๐
โญ HISTORY โญ
POSIX.1-2001, C89.
In glibc 2.17 and earlier, clock() was implemented on top of times(2). For improved accuracy, since glibc 2.18, it is implemented on top of clock_gettime(2) (using the CLOCK_PROCESS_CPUTIME_ID clock).
glow-up alert ๐ in glibc 2.17 and earlier she was implemented on top of times(2), but for improved accuracy, since glibc 2.18, she's built on clock_gettime(2) (using the CLOCK_PROCESS_CPUTIME_ID clock). the character development?? we love to see it โจ
๐ NOTES ๐
The C standard allows for arbitrary values at the start of the program; subtract the value returned from a call to clock() at the start of the program to get maximum portability.
okay so this is the portability hack you NEED in your life: the C standard allows for arbitrary values at the start of the program. so take a clock() reading at the very start, then subtract it. that's how you get maximum portability, bestie ๐ซถ
Note that the time can wrap around. On a 32-bit system where CLOCKS_PER_SEC equals 1000000 this function will return the same value approximately every 72 minutes.
and the wrap-around?? girl ๐ญ on a 32-bit system where CLOCKS_PER_SEC equals 1000000, this function will return the same value approximately every 72 minutes. like she just loops back around. no cap. plan accordingly ๐
๐ SEE ALSO ๐
clock_gettime(2), getrusage(2), times(2)
go read those too, they're all bangers ๐ฅ
and that's the whole page, bestie!! ๐ญ๐ this came from Linux man-pages 6.20, dated 2026-02-08, for clock(3). go track your CPU time responsibly, mwah ๐โจ๐ฆ
๐ฆ where this page comes from
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages 6.20
- ๐ the page's license: Linux-man-pages-copyleft
- Copyright 1993, Thomas Koenig <ig25@rz.uni-karlsruhe.de>
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms