测函数运行时间的程序模板及应用实例

程序模板:

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

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

//记录被测函数运行时间,以秒为单位
double duration;

int main()
{
	start = clock();//开始计时
	MyFunction();//把被测函数加在这里
	stop = clock();//停止计时
	duration = ((double)(stop - start))/CLK_TCK;
	return 0;
}

实例:

猜你喜欢

转载自blog.csdn.net/cv2017/article/details/81106804