C++计算代码片运行时间

#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;//根据两个时刻的差,计算出运行的时间
    cout<<"Time used is "<<time_length<<" second."<<endl;
   
    return 0;
}

你可能感兴趣的:(C++计算代码片运行时间)