当前位置:天才代写 > tutorial > C语言/C++ 教程 > C++:措施运行时间

C++:措施运行时间

2017-11-02 08:00 星期四 所属: C语言/C++ 教程 浏览:435

C++利用C语言的time库, 即可统计措施的运行时间;

头文件#include <ctime>

代码:

#include<iostream>  
#include<ctime>  
      
void do_something()  
{  
 for(int i=0;i<100000;i++)  
  for(int j=0;j<10000;j++)  
   ;  
}  
      
int main(int arg,char ** argv)  
{  
 clock_t start = clock();  
 do_something();  
 clock_t end = clock();  
 double time = static_cast<double>(end-start)/CLOCKS_PER_SEC;  
 std::cout << "time = " << time << std::endl;  
 return 0;  
}

 

    关键字:

天才代写-代写联系方式