Java性能 - 的ArrayList对阵列进行大量的速读 [英] Java Performance - ArrayLists versus Arrays for lots of fast reads

查看:130
本文介绍了Java性能 - 的ArrayList对阵列进行大量的速读的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个程序,我需要做100,000-1,000,000随机访问,在短短的时间读取到一个列表状物体尽量(以毫秒)一个细胞自动机般的程序。我想我用已经优化更新算法(跟踪活性细胞的效率,等等)。该列表确实需要改变大小,但性能并不重要。所以我想知道如果使用代替的ArrayList阵列的性能足以与许多打交道时有所作为的时间这么短跨度读取。目前,我使用的ArrayList

I have a program where I need to make 100,000 to 1,000,000 random-access reads to a List-like object in as little time as possible (as in milliseconds) for a cellular automata-like program. I think the update algorithm I'm using is already optimized (keeps track of active cells efficiently, etc). The Lists do need to change size, but that performance is not as important. So I am wondering if the performance from using Arrays instead of ArrayLists is enough to make a difference when dealing with that many reads in such short spans of time. Currently, I'm using ArrayLists.

编辑:
我忘了提:我只是存储整数,因此另一个因素是使用整型包装类(在的ArrayList的情况下)与整数(在阵列的情况下)。有谁知道,如果使用的ArrayList实际上将需要3指针的样子UPS(一个ArrayList中,一个底层的数组,一个用于整型> INT),其中作为数组将只需要1(阵列地址+偏移具体INT)?将热点优化额外看看UPS走?如何显著是那些额外的样子窗口?

I forgot to mention: I'm just storing integers, so another factor is using the Integer wrapper class (in the case of ArrayLists) versus ints (in the case of arrays). Does anyone know if using ArrayList will actually require 3 pointer look ups (one for the ArrayList, one for the underlying array, and one for the Integer->int) where as the array would only require 1 (array address+offset to the specific int)? Would HotSpot optimize the extra look ups away? How significant are those extra look ups?

EDIT2:
另外,我忘了提,我需要做的随机访问写入以及(写入,而不是插入)。

Also, I forgot to mention I need to do random access writes as well (writes, not insertions).

推荐答案

现在,您已经提到,你的数组实际上是基本类型数组,可以考虑在的Trove 库。

Now that you've mentioned that your arrays are actually arrays of primitive types, consider using the collection-of-primitive-type classes in the Trove library.

@viking报告显著在他的应用程序中使用的加速​​比特罗韦(十倍!) - 见注释。在另一面是,特罗韦集合类型不是类型与Java的标准集合的API兼容。所以特罗韦(或类似的库)将不会在所有情况下的答案。

@viking reports significant (ten-fold!) speedup using Trove in his application - see comments. The flip-side is that Trove collection types are not type compatible with Java's standard collection APIs. So Trove (or similar libraries) won't be the answer in all cases.

这篇关于Java性能 - 的ArrayList对阵列进行大量的速读的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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