C Standard Library

C <time.h> - CLOCKS_PER_SEC macro

The C <time.h> CLOCKS_PER_SEC macro expands to an expression of type clock_t equal to the number of clock ticks per second, as returned by clock() function. Dividing a count of clock ticks by this expression yields the number of seconds.

In the <time.h> header file, it is defined as follows:

#define CLOCKS_PER_SEC /*implementation defined*/             


The example below shows the usage of CLOCKS_PER_SEC macro.

#include <stdio.h>
#include <time.h>
int main (){
  clock_t start, finish;
  long product;

  start = clock();
  for(int i = 0; i < 100000; i++)
    for(int j = 0; j < 25000; j++) 
      product = i*j;

  finish = clock();

  //calculating the time difference 
  //in ticks and in milliseconds
  printf("Time taken = %ld ticks (%lf milliseconds)",
        (finish - start), 1000.0 * (finish - start)/CLOCKS_PER_SEC);   
  return 0;

The output of the above code will be:

Time taken = 6334701 ticks (6334.701000 milliseconds)

❮ C <time.h> Library