java short,integer,long performance [英] java short,integer,long performance

查看:212
本文介绍了java short,integer,long performance的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读到JVM存储内部短,整数和长4个字节。我从2000年的一篇文章中读到它,所以我不知道它现在是多么真实。

I read that JVM stores internally short, integer and long as 4 bytes. I read it from an article from the year 2000, so I don't know how true it is now.

对于较新的JVM,使用中是否有任何性能提升短整数/长?自2000年以来,实施的那部分是否发生了变化?

For the newer JVMs, is there any performance gain in using short over integer/long? And did that part of the implementation has changed since 2000?

谢谢

推荐答案

long  64 –9,223,372,036,854,775,808 to 9 ,223,372,036,854,775,807 
int   32 –2,147,483,648 to 2,147,483,647 
short 16 –32,768 to 32,767 
byte   8 –128 to 127 

使用您需要的东西,我认为由于范围较小而很少使用短裤big-endian格式。

Use what you need, I would think shorts are rarely used due to the small range and it is in big-endian format.

任何性能提升都会很小,但就像我说的那样,如果你的应用程序需要的范围比使用int的短范围更大。长型对你来说可能过于庞大;但这一切都取决于你的申请。

Any performance gain would be minimal, but like I said if your application requires a range more then that of a short go with int. The long type may be too extremly large for you; but again it all depends on your application.

如果您对空间有疑虑,应该只使用short (内存)否则使用int(在大多数情况下)。如果你正在创建数组,那么通过声明int和short类型的数组来尝试它。 Short将使用1/2的空间而不是int。但是如果你根据速度/性能运行测试,你会看到很少甚至没有差别(如果你正在处理数组),此外,你唯一能节省的就是空间。

You should only use short if you have a concern over space (memory) otherwise use int (in most cases). If you are creating arrays and such try it out by declaring arrays of type int and short. Short will use 1/2 of the space as opposed to the int. But if you run the tests based on speed / performance you will see little to no difference (if you are dealing with Arrays), in addition, the only thing you save is space.

同样是评论员提到的很长,因为长是64位。您将无法以4个字节存储长的大小(请注意长的范围)。

Also being that a commentor mentioned long because a long is 64 bits. You will not be able to store the size of a long in 4 bytes (notice the range of long).

这篇关于java short,integer,long performance的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆