clock Function

Calculates the processor time.

Include

<time.h>

Prototype

clock_t clock(void);

Return Value

Returns the number of clock ticks of elapsed processor time.

Remarks

If the target environment cannot measure elapsed processor time, the function returns -1 cast as a clock_t (i.e. (clock_t) -1). By default, the 16-bit compiler returns the time as instruction cycles.

Example

#include <time.h>  /* for clock  */
#include <stdio.h> /* for printf */

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