您的位置:首页 > 编程语言 > C语言/C++

【基础】查看程序运行所需时间--C++源代码(g++ 4.9.3)

2017-11-08 12:35 381 查看
#include <iostream>

#include <sys/time.h>

using namespace std;

int func()

{

        return 0;

}

int main()

{

        timeval start,end;

        gettimeofday(&start,NULL);

        for(int i=0;i<1000000;i++)

                func();

        gettimeofday(&end,NULL);

        double time = (end.tv_sec-start.tv_sec)*1000000 + (end.tv_usec-start.tv_usec);

    

        cout<<time<<endl;

        return 0;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: