开发者

speed of comparing: pointer-pointer versus int-int

On common modern CPUs (x86, x86_64 for exampl开发者_JAVA技巧e), is there a difference in the number of CPU cycles to compare two pointers and to compare two integers?


I am not sure but in x86_64 you can have an int being 4 bytes and a pointer 8 bytes. So if comparing 2 words and 2 halfwords differs, there should be a difference.


It's very likely that your performance will be more heavily impacted by how predictable the result of the comparison is than the type of the values being compared. If the branch predictor can get it right most of the time, the comparison is, in some sense, "free".

Also there's a decent chance the cache will be a limiting factor unless you're careful about your working set size.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜