如何以秒为单位打印C或Python代码的执行时间?
在C语言中,只需用此代码包装您的代码。您将获得执行时间,以秒为单位。
#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);
}
您可以在Python中使用datetime。