On a 32 bit system, operations on a 32 bit integer can be performed in a single machine register. But operations on a 64 bit integer require two machine registers, and are quite a bit less efficient than 32 bit operations. And of course, being twice the size, long
uses more memory than int
. If you have arrays of these types then you will consume your cache twice as fast if you use long
. That can also have performance implications.
So, if you can use int
, you should prefer it to long
. However, if the 32 bits of range afforded by int
are not sufficient for the correctness of your program, you would need to use long
.
Of course, even though operations on 64 bit integers, are less efficient when executed on a 32 bit machine, only profiling would tell you whether or not it actually matters.
Perhaps the bottom line is that programmers should not be wilfully profligate. Why use 64 bits, if 32 bits suffice?