您好,欢迎来到华佗小知识。
搜索
您的当前位置:首页c++程序时间统计

c++程序时间统计

来源:华佗小知识

如下所示,引入<time.h>我们就可以统计时间了:

#include<iostream>
#include<time.h>
#include<windows.h>
using namespace std;
int main() {
    time_t start, end;
    double cost;
    time(&start);
    for (int i = 0; i < 1000000000; i++) {
        int j = 0;
        j++;
        int k = 0;
        k++;
    }
    time(&end);
    cost = difftime(end, start);
    cout << cost << endl;
    system("pause");
    return 0;
}

 

在优化程序时方便查看效果。

 

转载于:https://www.cnblogs.com/zhuzhenwei918/p/71099.html

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- huatuo0.cn 版权所有 湘ICP备2023017654号-2

违法及侵权请联系:TEL:199 18 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务