C 语言 中 用来计算运行时间

#include <stdio.h>
#include <time.h>
#include <math.h>

/* clock_t 是 clock() 函数返回的变量类型 */
clock_t start, stop;

/* 记录被测量的运行时间,以秒为单位 */
double duration;

int main() {
	
	/* 开始计时 */
	start = clock();
	
	/* 计算运行的内容 */
	for(int i = 0; i < 1e6; i++) {
		printf("%d\n", i);
	}
	
	/* 结束计时 */
	stop = clock();
	
	/* 计算运行时间 */
	duration = ((double) (stop - start))/CLK_TCK;
	
	/* 打印运行时间 */
	printf("运行时间:%f\n", duration);
	
}


结果
C 语言 中 用来计算运行时间

相关文章:

  • 2021-12-10
  • 2021-12-11
  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-12-16
  • 2022-12-23
猜你喜欢
  • 2021-12-28
  • 2021-12-18
  • 2022-12-23
  • 2022-12-23
  • 2022-02-11
  • 2022-12-23
相关资源
相似解决方案