1

How to print the execution time in seconds of C or Python Code?

Roberto Caboni
  • 7,252
  • 10
  • 25
  • 39

2 Answers2

1

In C , just wrap your code with this code.You will get the execution time in seconds.

#include <time.h>
{
 clock_t start, end;
 double cpu_time_used;
 start = clock();

 /* Your Code */

 end = clock();
 cpu_time_used = ((double) (end - start)) / CLOCKS_PER_SEC;
 printf("The Execution Time In Seconds is : %lf",cpu_time_used);
}
krishnaacharyaa
  • 14,953
  • 4
  • 49
  • 88
1

You can use datetime in Python for that.

start_time = datetime.datetime.now()
<your program/ lines of code in the Python script/program>
-----
-----
-----
print (datetime.datetime.now() - start_time)

This should give the time. You can also use timeit.timeit() I guess.