Float vs Double performance in C# considering cache
I checked and could find numerous posts about performance of float vs double (here is one, and here is another). In most cases, it is said that they have the same performance because they are converted by FPU to 10-bye real numbers. But I'm still not convinced. What if the locality issues are considered appropriately? Consider doing bitwise XOR on large number of bits, counting none 0 bits will take considerably less time when the data fits the cache (float). Doing XOR and bit population count with regular (non SIMD instructions) will drive processing time a lot longer. I tried to write some test to confirm it, but it is not easy to get everything right.
One question is does these two types converted to the same size in the cache?
In general, I was wondering if anyone can characterize the behavior 开发者_如何学Cof these 2 choices in different situations?
What if the locality issues are considered appropriately?
Still the same because those are normally not as high as you think. If you deal with float and double except just copying it, there is some significant time spent actually CALCULATING. Your XOR example is a good example where you think wrong. XOR is a SIMPLE EASY FAST operation, so coherency is important. With floats you spend a lot more time doing the maths in most cases.
精彩评论