开发者

speed of comparing: pointer-pointer versus int-int

开发者 https://www.devze.com 2023-03-07 16:14 出处:网络
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 ca

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

精彩评论

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