如何知道程序的执行时间[重复项]

问题描述 投票:0回答:2

如何以秒为单位打印C或Python代码的执行时间?

python c runtime code-snippets
2个回答
0
投票

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

0
投票

您可以在Python中使用datetime。

© www.soinside.com 2019 - 2024. All rights reserved.