clock()

A program relative invocation of the system time.

  #include <time.h>
  
  clock_t clock(void);    
Remarks

Use this function to obtain values of type clock_t, which may be used to calculate elapsed times during the execution of a program. To compute the elapsed time in seconds, divide the clock_t value by CLOCKS_PER_SEC, a macro defined in time.h.

The programmer should be aware that clock_t, defined in time.h, has a finite size that varies depending upon the target system.

The function returns a value of type clock_t representing the approximation of time since the system was started. The function does not return an error value if an error occurs.

This facility may not be available on some configurations of the EWL.

Listing: Example of clock() usage

#include <time.h>

#include <stdio.h>

#define MAXLOOP 100000

int main()

{

clock_t start;

clock_t end;

double secs = 0;

int i;

start = clock();

end = clock();

for (i = 0; i < MAXLOOP; ++i)

{

; /* Do nothing. */

}

secs = (double)(end - start) / (double)CLOCKS_PER_SEC;

printf("Elapsed seconds = %f \n", secs);

return 0;

}

Output:

Elapsed seconds = 0.033333