How to print the execution time in seconds of C or Python Code?
Asked
Active
Viewed 99 times
1
-
Or [Execution time of C program](https://stackoverflow.com/questions/5248915/execution-time-of-c-program) – David Buck May 28 '20 at 17:54
2 Answers
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);
}
Krishna Acharya
- 542
- 3
- 18
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.
Rithwik Rajendran
- 99
- 7