[英]why a uint32_t vs uint64_t speed difference?
Trying to understand something about how g++/cpu processes integers at runtime. 试图了解有关g ++ / cpu如何在运行时处理整数的信息。
I'm measuring how long the following function takes to run: 我正在测量以下功能需要运行多长时间:
template<class T>
void speedTest() {
for(T d=0;d<4294967295u;d++)int number;
}
This simple method will run a dumb loop the max value of uint32_t many times 这个简单的方法将多次运行一个uint32_t最大值的哑循环
and when I call: 当我打电话时:
speedTest<uint32_t>();
the software takes an average of 8.15 seconds but when I call: 该软件平均需要8.15秒,但在我致电时:
speedTest<uint64_t>();
the software takes an average of 10.35 seconds. 该软件平均需要10.35秒。
Why is this happening? 为什么会这样呢?
Some possible reasons: 一些可能的原因:
int number;
不管int number;
,都可以完全优化掉这种无副作用的循环int number;
(could just be for(T d=0;d<4294967295u;d++);
) (可能只是for(T d=0;d<4294967295u;d++);
) You could continue your investigation/exercise by providing some assembly. 您可以通过提供一些程序集来继续进行调查/练习。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.