首页 > 其他 > 详细

计算程序运行时间

时间:2015-02-02 19:51:41      阅读:229      评论:0      收藏:0      [点我收藏+]
#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;  
}

技术分享

计算程序运行时间

原文:http://www.cnblogs.com/lwngreat/p/4268505.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!