注:此文中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上才跑成功