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