5 ms·
If I'm reading the table under "fast instruction, slow instruction" correctly, float multiplication has half the reciprocal throughput of integer multiplication
by spekcular 5y ago
If I'm reading the table under "fast instruction, slow instruction" correctly, float multiplication has half the reciprocal throughput of integer multiplication, which means float multiplication has twice the throughput.
So, if I want to multiply a bunch of integers together, does this mean it's faster for me to represent them as floats (even though I don't need the additional precision)?
- NohatCoder 5y agoIt depends on the processor, but yes in some cases using floats would be faster for this reason. Please note that floats don't have "additional" precision, they have a different structure that means they can express a different set of numbers. Integers should in general always be preferred when the data you deal with is of integral nature. Even if your CPU can do some instructions faster with floats it is generally not the kind of optimization you would want to make. You would end up making things more complicated for little practical benefit. Funny thing by the way, integer arithmetic units are generally cheaper to make than float units, but most multiply/division heavy code is floating point, so CPU makers prioritise the floating point units.
- spekcular 5y agoThank you for the detailed explanation.