C/C++中代码段运行时间/程序运行时间

include<iostream>
 #include<ctime>
 using namespace std;
 int main()
 {
     clock_t startTime,endTime;
     for (int i = 0; i < 2147483640; i++)
     {
         i++;
     }
     startTime = clock();//计时开始
     for ( i = 0; i < 2147483640; i++)
     {
         i++;
     }
     endTime = clock();//计时结束
     cout << "The run time is:" <<(double)(endTime - startTime) / CLOCKS_PER_SEC << "s" << endl;
     cout << "The run time is:" << (double)clock() /CLOCKS_PER_SEC<< "s" << endl;
     system("pause");
     return 0;
 }

在这里插入图片描述

发布了20 篇原创文章 · 获赞 3 · 访问量 831

猜你喜欢

转载自blog.csdn.net/weixin_45019478/article/details/104857557