算法效率计算方法之一【耗时计算】

注:此文中step1()函数和step2()函数是求同一个题的不同方法(详细函数实现略去未写)
某算法耗时计算必须包含头文件Windows.h!!!!!
在该算法前后分别用两个变量接收 GetTickCount64();最后再输出两变量相减的结果。
即:

	long long start1 = GetTickCount64();
	step1(n);           //想计算这个算法耗时
	long long end1 = GetTickCount64();
	
	cout << end1 - start1 << endl;    //相差即此算法耗时

总:

#include <Windows.h> 
………………
………………
int main()
{
	int n;
	cin >> n;
	
	long long start1 = GetTickCount64();
	step1(n);           //想计算这个算法耗时
	long long end1 = GetTickCount64();
	
	cout << "第一个算法耗时:" << endl;
	cout << end1 - start1 <<"ms"<< endl;    //相差即此算法耗时

	long long start2 = GetTickCount64();
	step2(n);            //想计算这个算法耗时
	long long end2 = GetTickCount64();
	
	cout << "第二个算法耗时:" << endl;
	cout << end2 - start2 <<"ms"<< endl;    //相差即此算法耗时

	system("pause");
	return 0;
}

测试结果:在这里插入图片描述
0ms说明已经很快了~~
Devc++上好像不行,在vs上才跑成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值