totn C Functions

C Language: clock function
(Processor Clock)

In the C Programming Language, the clock function returns the elapsed processor time (as measured in clock ticks) since the beginning of the program execution.

Syntax

The syntax for the clock function in the C Language is:

clock_t clock(void);

Returns

The clock function returns the elapsed processor time (as measured in clock ticks) since the beginning of the program execution.

If you want to determine the elapsed time in seconds, take the result of the clock function and divide by CLOCKS_PER_SEC.

If there is an error (ie: the time is unavailable or can not be represented), the clock function will return -1.

Required Header

In the C Language, the required header for the clock function is:

#include <time.h>

Applies To

In the C Language, the clock function can be used in the following versions:

  • ANSI/ISO 9899-1990

Similar Functions

Other C functions that are similar to the clock function:

See Also

Other C functions that are noteworthy when dealing with the clock function: