码迷,mamicode.com
首页 > 编程语言 > 详细

c++程序时间统计

时间:2018-04-29 16:21:18      阅读:117      评论:0      收藏:0      [点我收藏+]

标签:namespace   windows   div   art   mes   use   using   int   ftime   

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

 

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

 

c++程序时间统计

标签:namespace   windows   div   art   mes   use   using   int   ftime   

原文地址:https://www.cnblogs.com/zhuzhenwei918/p/8971099.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!