# clock Function

Determines the processor time used.

Attention: This function is not implemented by MPLAB XC8 C compilers.

Include

<time.h>

Prototype

clock_t clock(void);

Return Value

Returns the number of clock ticks of elapsed processor time.

Remarks

Divide the value returned by this function by the value of the CLOCKS_PER_SEC macro to determine a time in seconds.

If the target environment cannot measure elapsed processor time, the function returns -1 cast as a clock_t (i.e. (clock_t) -1).

When using XC16, this function uses the device Timer2 and Timer3 to compute clock ticks. By default, the compiler returns the time as instruction cycles.

Example

#include <time.h>
#include <stdio.h>

volatile int i;

int main(void)
{
clock_t start, stop;
int ct;

start = clock();
for (i = 0; i < 10; i++)
stop = clock();
printf("start = %ld\n", start);
printf("stop = %ld\n", stop);
}

Example Output

start = 0
stop = 317