首页 > 代码库 > 计算程序运行时间

计算程序运行时间

#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;  }

技术分享

计算程序运行时间