如下所示,引入<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;
}

 

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

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-12-15
  • 2022-12-23
  • 2022-02-07
  • 2021-05-23
  • 2021-05-23
  • 2021-07-08
猜你喜欢
  • 2022-01-23
  • 2021-07-08
  • 2022-12-23
  • 2021-10-29
  • 2021-09-29
  • 2021-11-05
  • 2022-01-08
相关资源
相似解决方案