如何知道程序的执行时间
How to know the execution time of a program
如何以秒为单位打印 C 或 Python 代码的执行时间?
在 C 中,只需用这个 code.You 包装您的代码即可获得以秒为单位的执行时间。
#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 中的日期时间。
start_time = datetime.datetime.now()
<your program/ lines of code in the Python script/program>
-----
-----
-----
print (datetime.datetime.now() - start_time)
这应该给时间。你也可以使用 timeit.timeit() 我猜。
如何以秒为单位打印 C 或 Python 代码的执行时间?
在 C 中,只需用这个 code.You 包装您的代码即可获得以秒为单位的执行时间。
#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 中的日期时间。
start_time = datetime.datetime.now()
<your program/ lines of code in the Python script/program>
-----
-----
-----
print (datetime.datetime.now() - start_time)
这应该给时间。你也可以使用 timeit.timeit() 我猜。