输出运行时间
1、timeGetTime()函数
DWORD Start = timeGetTime();
//这里运行你的程序代码
DWORD End = timeGetTime();
则(End-Start)就是你的程序运行时间, 以毫秒为单位
虽然返回的值单位应该是ms,但精度只有10ms。
2、clock()函数
用clock()函数,得到系统启动以后的毫秒级时间,然后除以CLOCKS_PER_SEC,就可以换成“秒”,标准c函数。
clock_t clock ( void );
#include <time.h>
clock_t t = clock();
long sec = t / CLOCKS_PER_SEC;
他是记录时钟周期的
来段程序测试一下
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
time_t begin,end;
double ret;
begin=clock();
for(int i=0;i<100;i++)
cout<<"you are a good child!"<<endl;
//这里加上你的代码
end=clock();
ret=double(end-begin)/CLOCKS_PER_SEC;
cout<<"runtime: "<<ret<<endl;
}