clock - C time.h

C examples for time.h:clock

Type

function

From


<ctime>
<time.h>

Description

Returns the processor time consumed by the program.

Prototype

clock_t clock (void);

Parameters

none

Return Value

The number of clock ticks elapsed since an epoch.

On failure, the function returns a value of -1.

Demo Code


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

int my (int n) {
  int i,j;// w  w w.  j  a va  2s .co m
  int freq=n-1;
  for (i=2; i<=n; ++i) 
    for (int x=0; x<=100000; ++x)   
        for (j=sqrt(i);j>1;--j) 
          ;
  return freq;
}

int main ()
{
  clock_t t;
  int f;
  t = clock();
  printf ("Calculating...\n");
  f = my (99999);
  printf ("done!\n");
  t = clock() - t;
  printf ("It took me %d clicks (%f seconds).\n",t,((float)t)/CLOCKS_PER_SEC);
  return 0;
}

Related Tutorials