在算法比较中,耗时是一个重要的指标。每次都要去搜别人的博客,今天摘抄一下askunix_hjh的博客,感谢博主。
原文记录了三种办法,我选择了其中比较易懂的。
GetTickCount是函数。GetTickCount返回(retrieve)从操作系统启动所经过(elapsed)的毫秒数,它的返回值是DWORD。
#include<iostream>
#include<Windows.h>
using namespace std;
int main()
{
DWORD start_time = GetTickCount();
for (int i = 0; i < 100000000; i++)
{
i++;
}
DWORD end_time = GetTickCount();
cout << "The run time is:" << (end_time - start_time) << "ms!" << endl;
system("pause");
return 0;
}