首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >C++记录程序运行时间

C++记录程序运行时间

作者头像
ClearSeve
发布于 2022-02-10 18:39:18
发布于 2022-02-10 18:39:18
1.3K0
举报
文章被收录于专栏:ClearSeveClearSeve

方式一

代码语言:javascript
复制
#include<iostream>
#include<ctime>
using namespace std;
int main()
{
    clock_t startTime,endTime;
    // 计时开始
    startTime = clock();
    for (int i = 0; i < 2147483640; i++)
    {
        i++;
    }
    // 计时结束
    endTime = clock();
    cout << "运行时间: " <<(double)(endTime - startTime) / CLOCKS_PER_SEC << "秒" << endl;
    system("pause");
    return 0;
}
// 注释在:VC++6.0中可以用CLK_TCK替换CLOCKS_PER_SEC。

方式二

代码语言:javascript
复制
clock_t startTime, endTime;
// 计时开始
startTime = clock();
// 计时结束
endTime = clock();
CString strLog;
strLog.Format(_T("运行时间: %0.3lf秒\r\n"), (double)(endTime - startTime) / CLOCKS_PER_SEC);
OutputDebugString(strLog);
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2022年1月18日,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档