Trove 集合类学习
2015-06-05 10:48
302 查看
trove把java原生的集合类范型去掉,而用具体的类型集合来取代。这造成了类型比较多,但是同时针对具体类型优化后的效果比java原生集合类还是效果上要好些。
对HashMap<Integer,Integer>和TIntIntHashMap做了一个对比,
i=1000000时,TIntIntHashMap在内存上和时间开销上都明显好于HashMap<Integer,Integer>,说明在集合元素较多情况下,trove的hashmap比java原生map效果更好。
这主要因为trove做hash时采用的开放探测选址,java原生map采用的是链表。前者不用保存链表节点,所以内存占用较少,速度较快。但是前者如果没有足够的空间索引,则效率会很低。
对HashMap<Integer,Integer>和TIntIntHashMap做了一个对比,
public static void main(String args[]) throws JSONException { long start = System.currentTimeMillis(); // System.gc(); long initSize = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); TIntIntHashMap map = new TIntIntHashMap(); // Map<Integer,Integer> map = new HashMap<Integer,Integer>(); int i = 0; while (i++ < 1000000) { map.put(i, i); } // System.gc(); long afterUseSize = Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory(); System.out.println("cost time:" + (System.currentTimeMillis() - start)); System.out.println("use memory:" + (afterUseSize - initSize)); }发现i=10000时,HashMap<Integer,Integer>内存使用情况比TIntIntHashMap差,但是时间开销上要好。
i=1000000时,TIntIntHashMap在内存上和时间开销上都明显好于HashMap<Integer,Integer>,说明在集合元素较多情况下,trove的hashmap比java原生map效果更好。
这主要因为trove做hash时采用的开放探测选址,java原生map采用的是链表。前者不用保存链表节点,所以内存占用较少,速度较快。但是前者如果没有足够的空间索引,则效率会很低。
相关文章推荐
- Hosting WCF Service
- c3p0数据库连接池的使用
- 线程中更新ui
- 【Clone Graph】cpp
- 应届生必读!应届生落户北京的那些事儿!
- jQuery的三种$()
- 关于Java通过JNI调用C 动态链接库(DLL)
- Vmware 11 安装 os x
- C#取色器
- Extjs杂记录
- Vmware复制移动虚拟机网卡启动失败
- Openstack keystone setup.py和setup.cfg的解析
- C# WinForm捕获全局异常
- Topcoder SRM660 DIV1 250 Coversta(暴力枚举)
- mysql导入导出sql文件
- 学无止境-每日一得
- 一键导出excel
- IO类
- Java中的正则表达式中的中文
- json和数组的区别