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;
}

 

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

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM