Home > Electronics Tutorials > C Language Tutorial > time.h - clock

C Language Programming Library Reference Guide

time.h - clock

Declaration: clock_t clock(void); Returns the processor clock time used since the beginning of an implementation-defined era (normally the beginning of the program). The returned value divided by CLOCKS_PER_SEC results in the number of seconds. If the value is unavailable, then -1 is returned.

Example:

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

int main(void)
{
  clock_t ticks1, ticks2;

  ticks1=clock();
  ticks2=ticks1;
  while((ticks2/CLOCKS_PER_SEC-ticks1/CLOCKS_PER_SEC)<1)
    ticks2=clock();

  printf("Took %ld ticks to wait one second.\n",ticks2-ticks1);
  printf("This value should be the same as CLOCKS_PER_SEC which is %ld.\n",CLOCKS_PER_SEC);
  return 0;
}

Note: To report broken links or to submit your projects, tutorials please email to Webmaster

Discover

     more......