作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
<分区>
作为实验,我一直在运行以下代码块。我在这里估算了 for
循环中不同迭代次数所花费的时间。
std::vector<double> numIt= {1e2, 1e4, 1e6, 1e8, 1e9, 1e10,1e11};
for(int i=0; i< (int) numIt.size() ; i++ )
{
int tmp=0;
std::chrono::high_resolution_clock::time_point t1 = std::chrono::high_resolution_clock::now();
for (int j=0; j< numIt[i]; j++)
{
tmp=i-j;
}
std::chrono::high_resolution_clock::time_point t2 = std::chrono::high_resolution_clock::now();
auto durationFPextraction = std::chrono::duration_cast<std::chrono::milliseconds>( t2 - t1 ).count();
std::cout <<i<< "\t"<< tmp<<"\t"<<numIt[i] << "\t" << durationFPextraction <<std::endl;
}
它打印以下内容,并且已经运行了几个小时以遍历 1e+10
长度 for
循环。如果花费的时间是线性的,它不应该花费 ~14000 毫秒(14 秒)吗?
0 -99 100 0
1 -9998 10000 0
2 -999997 1e+06 2
3 -99999996 1e+08 144
4 -999999995 1e+09 1394
我是一名优秀的程序员,十分优秀!