Search code examples
pythoncruntimecode-snippets

How to know the execution time of a program


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


Solution

  • 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);
    }