Reputation: 26882
I heard that using short
s on 32bit system is just more inefficient than using int
s. Is this the same for int
s on a 64bit system?
Python recently(?) basically merged int
s with long
and has basically a single datatype long
, right? If you are sure that your app. will only run on 64bit then, is it even conceivable (potentially a good idea) to use long for everything in Java?
Upvotes: 2
Views: 1534
Reputation: 718758
If you are sure that your app. will only run on 64bit then, is it even conceivable (potentially a good idea) to use long for everything in Java?
Bad idea, IMO
Even if there is a difference between using int
and long
on a 64-bit JVM (which I think is highly doubtful), it won't be significant enough over the entire application, including the libraries that you depend on to warrant using long
for everything.
And there are some potential problems:
long[]
versus int[]
. (The reason I think there won't be a significant performance difference is that the issue, if there is one, will be fetching and storing non-aligned int-32s. But if that is so, the JVM designers are likely to ensure that int-32 fields are always aligned on 64-bit word addresses. JVMs typically do this already with int-8 and int-16 on 32bit architectures ... )
Upvotes: 2
Reputation: 12560
A Python long
has arbitrary precision, it's not 64-bit. Python 3 changed long
to int
, so now there is only one integral type of arbitrary precision, this saves a lot of work for the programmer. Java's int is 32-bit, it's long is 64-bit. A 64-bit processor can generally perform better than a 32-bit processor on a 64-bit integer.
Using 32-bit integers on a 64-bit platform isn't expensive, at least not in x64. It makes no sense to choose a 32-bit over 64-bit int or vise-versa in Java just for performance reasons. If you used two 32-bit ints instead of one 64-bit int, it would be slower no matter what. Similarily, if you use 64-bit where you could have used 32-bit, it will be slower on some platforms. In other words, use the right data type for your problem domain.
Upvotes: 2