Skip to main content
added 506 characters in body
Source Link
Sunil Bojanapally
  • 12.8k
  • 4
  • 37
  • 47

If you are looking how much time is consumed in executing your program from Unix shell, make use of Linux time as below,

time ./a.out 

real    0m0.001s
user    0m0.000s
sys     0m0.000s

Secondly if you want time took in executing number of statements in the program code (C) try making use of gettimeofday() as below,

#include <sys/time.h>
struct timeval  tv1, tv2;
gettimeofday(&tv1, NULL);
/* Program code to execute here */
gettimeofday(&tv2, NULL);
printf("Time taken in execution = %f seconds\n",
     (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
     (double) (tv2.tv_sec - tv1.tv_sec));

If you are looking how much time is consumed in executing your program from Unix shell, make use of Linux time as below,

time ./a.out 

real    0m0.001s
user    0m0.000s
sys     0m0.000s

If you are looking how much time is consumed in executing your program from Unix shell, make use of Linux time as below,

time ./a.out 

real    0m0.001s
user    0m0.000s
sys     0m0.000s

Secondly if you want time took in executing number of statements in the program code (C) try making use of gettimeofday() as below,

#include <sys/time.h>
struct timeval  tv1, tv2;
gettimeofday(&tv1, NULL);
/* Program code to execute here */
gettimeofday(&tv2, NULL);
printf("Time taken in execution = %f seconds\n",
     (double) (tv2.tv_usec - tv1.tv_usec) / 1000000 +
     (double) (tv2.tv_sec - tv1.tv_sec));
Source Link
Sunil Bojanapally
  • 12.8k
  • 4
  • 37
  • 47

If you are looking how much time is consumed in executing your program from Unix shell, make use of Linux time as below,

time ./a.out 

real    0m0.001s
user    0m0.000s
sys     0m0.000s