C++计算代码运行时间

参考:http://blog.csdn.net/songzige/article/details/51181934

#include "time.h"  

using namespace std;  

int main(){  
    clock_t start, finish;  
    double time_length;  

    start = clock();//start  
    //计算时间的代码片  
    finish = clock();//finish  

    time_length = (double)(finish - start) / CLOCKS_PER_SEC;//根据两个时刻的差,计算出运行的时间  ,而且CLOCKS_PER_SEC = 1000 的
    cout<<"Time used is "<" second."<return 0;  
} 

你可能感兴趣的:(c++,C++基础知识)