Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>There are two different questions here: speed when reading/writing, and arithmetic performance. Those are orthogonal. When reading or writing a large array, of course, the speed depends on the amount of bytes read as O(N), so using <code>short</code> over <code>int</code> (considering VC++) would slash the time by ~1/2.</p> <p>For arithmetic, once the operands are in registers, the size of the type doesn't matter so much. IIRC, between types in the same category, it is actually the same (so <code>short</code> isn't any faster or slower than <code>int</code>). Using 64-bit integer types on a 32-bit platform will have a penalty, naturally, since there's no single instruction to handle that. Floating-point types, on the other hand, are simply slower than all integral types, even though <code>sizeof(float)==sizeof(int)</code> on VC++. But, again, operations on <code>float</code> aren't any faster than operations on <code>double</code>; this is assuming default FPU settings, which promote all operands to 80-bit extended floats - this can be disabled to squeeze out a bit more out of using <code>float</code>s, IIRC.</p> <p>The above is VC++ and x86 specific, as requested by the question. Other platform, and especially other architecture, can differ radically.</p> <p>The best one data type that is most efficient to work with as number counter (low or not) is <code>int</code> - usually regardless of the architecture and implementation (as the Standard recommends it to be the preferred word size of the platform).</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload