您的位置:首页 > 其它

计算程序运行时间

2015-02-02 19:07 141 查看
#include <iostream>
#include <time.h>
int main(void)
{
int sum = 0;
time_t t,t1;        time(&t);        //t = time(NULL);
std::cout<<ctime(&t);        //单位为秒

int star = clock();                //单位毫秒
for (int i=1; i <=10000; ++i)
{
sum = sum+i;
}
std::cout<<sum<<std::endl;
int stop = clock();
std::cout<<stop - star<<"毫秒"<<std::endl;
time(&t1);
int t3 = t1-t;
std::cout<<t3<<" 秒"<<std::endl;
std::cout<<ctime(&t1);
system("pause");
return 0;
}


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: