C Time Functions - C clock






Returns an approximation of processor time used by the program.

Example


#include <stdio.h> /* printf */
#include <time.h> /* clock_t, clock, CLOCKS_PER_SEC */
#include <math.h> /* sqrt */
/*  ww  w . ja v a 2s  . c om*/
int main (){
  clock_t t;
  int f = 10;
  t = clock();
  printf ("%d\n",f);
  printf ("%d\n",f);
  printf ("%d\n",f);
  printf ("%d\n",f);
  printf ("%d\n",f);
  printf ("%d\n",f);
  t = clock() - t;
  printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  return 0;
} 

       

The code above generates the following result.