开发者

Float vs Double performance in C# considering cache

开发者 https://www.devze.com 2023-03-09 18:00 出处:网络
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 converte

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.

0

精彩评论

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

关注公众号