而不是将通过多头在整数64位的java中获益 [英] Will using longs instead of ints benefit in 64bit java

查看:99
本文介绍了而不是将通过多头在整数64位的java中获益的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在64位虚拟机,将使用多头而不是整数做在性能方面没有更好的考虑到多头是64位的Java,因此拉动和处理64位字可能是在64位系统快了拉32位字。 (我期待了很多号,但我一直在寻找一个详细的解释)。

In a 64 bit VM, will using longs instead of ints do any better in terms of performance given that longs are 64 bits in java and hence pulling and processing 64 bit word may be faster that pulling 32bit word in a 64 bit system. (I am expecting a lot of NOs but I was looking for a detailed explanation).

修改:我暗示拉动和处理64位字可能会更快的拉动32位字在64位系统,因为我假设在64位系统上,拉着32比特数据会要求你先得​​到64位字,然后掩盖了前32位。

EDIT: I am implying that "pulling and processing 64 bit word may be faster that pulling 32bit word in a 64 bit system" because I am assuming that in a 64 bit system, pulling a 32 bit data would require you to first get the 64 bit word and then mask the top 32 bits.

推荐答案

使用 INT 很可能将放缓你下来一般。

Using long for int probably will slow you down in general.

您杀到是否 INT 64位CPU需要额外的处理时间。这是一个现代化的流水线CPU的可能性极小。我们可以用一个小程序轻松地进行测试。它操作的数据应该是足够小,适合在L1高速缓存,这样,我们正在测试这一特殊问题。在我的机器(64位的Intel Core2四)有基本上没有区别。

You immediate concern is whether int on 64 bit CPU requires extra processing time. This is highly unlikely on a modern pipelined CPU. We can test this easily with a little program. The data it operates on should be small enough to fit in L1 cache, so that we are testing this specific concern. On my machine (64bit Intel Core2 Quad) there's basically no difference.

在一个真正的应用程序,大部分的数据无法驻留在CPU缓存。我们必须担心从主存储器向高速缓冲存储器是相对非常缓慢且通常为一个瓶颈加载数据。这样的装载作品高速缓存行的单位,这是64个字节或更多,因此加载一个 INT 将采取相同的时间。

In a real app, most data can't reside in CPU caches. We must worry about loading data from main memory to cache which is relatively very slow and usually a bottleneck. Such loading works on the unit of "cache lines", which is 64 bytes or more, therefore loading a single long or int will take the same time.

然而,使用将浪费precious缓存空间,所以高速缓存未命中将增加,这是非常昂贵的。 Java的堆空间还强调,这样GC活动将会增加。

However, using long will waste precious cache space, so cache misses will increase which are very expensive. Java's heap space is also stressed, so GC activity will increase.

我们可以通过阅读大量长[] INT [] 数组的元素相同数量的证明这一点。他们的方式大于缓存可以包含的内容。长版需要65%以上的时间在我的机器上。该试验是通过与内存>缓存吞吐量的约束,并且长[]存储器体积较大的100%。 (为什么没有采取100%以上的时间是超越我,显然其他因素在起作用太)

We can demonstrate this by reading huge long[] and int[] arrays with the same number of elements. They are way bigger than caches can contain. The long version takes 65% more time on my machine. The test is bound by the throughput of memory->cache, and the long[] memory volume is 100% bigger. (why doesn't it take 100% more time is beyond me; obviously other factors are in play too)

这篇关于而不是将通过多头在整数64位的java中获益的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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