CPP计算某一段程序所花费的时间

//计算某一段程序所花费的时间
#include<iostream>
#include<ctime>
using namespace std;

void Delay();//测试函数,用来测试运行时间

int main()
{
    clock_t startT, endT;
    double duration;
    cout<<"Start..."<<endl;
    
    startT = clock();//获取cpu绝对钟数
    Delay();
    endT = clock();
    duration = double(endT - startT)/CLOCKS_PER_SEC;//计算运行的时间,秒为单位
    
    cout<<"程序运行花费的时间为: "<<duration<<endl;
     
    return 0;
 } 
 
 void Delay()
 {
    for(int i = 0;i<1000000000;i++)
    {
        
    }
    return;
 }
输出.PNG
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容