| Name | Description | Notes | Source | Availability | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
CLOCKS_ |
Granularity of execution-time clock | M | <time.h> |
C89 | C90 | C95 | C99 | C11 | |||
clock() |
Get execution time | (·) | <time.h> |
C89 | C90 | C95 | C99 | C11 | |||
clock_t |
Execution-time type | T | <time.h> |
C89 | C90 | C95 | C99 | C11 | |||
#include <time.h>
clock_t clock(void);
The function clock
returns the current time related to the start of the
program's execution. Divide the result by CLOCKS_,
which is an arithmetic constant, to get that time in
seconds. clock_t
is a real
type. The value (clock_t)
-1 is returned if program duration is unavailable.
The initial value is not necessarily zero. You should call
clock
close to the start of the program's execution (early in
main) to obtain an epoch
closely representing the start of the program, and subtract
it from subsequent values before dividing. For example:
clock_t zero_time; int main(void) { zero_time = clock(); . . . } // Later… double runtime = (clock() - zero_time) / CLOCKS_PER_ ;SEC