问题描述
可能重复:结果
performance无符号VS符号整数
我已经读的地方,它是一个很小的有点快于 x86_64的
比较在<$ C $签署整数
C> C / C ++ 相比,无符号整数
,例如: 的for(int我...
)是(UINT我...)比更快。
I have read somewhere that it's a tiny bit faster on
x86_64
to compare signed ints
in C/C++
compared to unsigned ints
, e.g. for (int i...
) is "faster" than for (uint i...)
.
是这样吗?为什么是真的吗?我知道其中的差别是超小,但无论如何。
Is that true? Why is that true? I know the difference is super small, but anyway.
推荐答案
您最好引用来源为这种说法,这是它的脸可笑了。
You'd better cite a source for such a claim, which is ridiculous on the face of it.
我们正在谈论的x86_64,这意味着现代的处理器。这些的ALU将完成整数加法,减法,和/或在单个时钟周期比较(当然高速缓存未命中将需要更长的时间,但只对数据的大小和存储器布局取决于,未签名岬)。或甚至更低,用SIMD协处理器
We're talking about x86_64, which means modern processors. These ALUs will complete integer addition, subtraction, and/or comparison in a single clock cycle (cache misses will of course take longer, but depend only on the size and memory layout of the data, not signed-ness). Or even less, with the SIMD coprocessor.
我最好更容易相信有两种类型的比较之间的微小功率差,但不产生速度差。
I'd more likely to believe that there's a slight power difference between the two types of comparison, but not a speed difference.
现在,它可能是对于特定的编译器,定位于x86_64平台时code代是相较于其他一个数据类型更糟。但是,这将是一个非常特殊的情况下,并不太可能适用于所有x86_64的编译器。仍然,我怀疑缓存效果或后台进程是影响性能的测量(即测量时间每个进程花费将由上下文切换无效缓存受到影响,甚至性能计数器)。
Now, it is possible that for a particular compiler, code generation is worse for one data type vs the other when targeting the x86_64 platform. But that would be a very specialized case, and not likely to apply to all x86_64 compilers. And still, I'd suspect cache effects or background processes were affecting the performance measurement (even performance counters that measure time spent per-process will be affected by a context switch invalidating caches).
这篇关于相比较快比无符号整数签署的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!