关于Map和List的性能测试报告

来源:互联网 发布:淘宝网外贸原单 编辑:程序博客网 时间:2024/06/06 08:26
<script type="text/javascript">google_ad_client = "pub-8800625213955058";/* 336x280, 创建于 07-11-21 */google_ad_slot = "0989131976";google_ad_width = 336;google_ad_height = 280;//</script><script type="text/javascript"src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>说明:我所涉及到的试验代码,均是针对于1百万条记录,我的硬件配置如下:CPUP4 1.5G,256M DDR的内存。如果要试验其代码,要采用这种方式运行:java -Xms128M -Xmx250M TestMap1,对内存容量的要求Map对象高于List。因为Map除了Value外还需要一个Object的Key,从而增大了Map的容量。试验代码如下: import java.util.*; public class TestMap { public static void main(String[] args) { System.out.println("begin>>>>>>>>>>>>>>"); long sm = Runtime.getRuntime().totalMemory(); System.out.println("Begin Memory :" sm); Map m = new Hashtable(); //LinkedList tmpList = new LinkedList(); for (int i=0;i<1000000;i ) { m.put("" i,"i=" i); //Integer integer = new Integer(i); //tmpList.add(integer); } long em = Runtime.getRuntime().totalMemory(); System.out.println("End Memory :" em); System.out.println("End-Start Memory :" (em - sm)); //walkList(tmpList); System.out.println("<<<<<<<<<<<<<<<>>>>>>>>>>>>>"); long sm = Runtime.getRuntime().totalMemory(); System.out.println("Begin Memory :" sm); Map m = new Hashtable(); //LinkedList tmpList = new LinkedList(); for (int i=0;i<1000000;i ) { m.put("" i,"i=" i); //Integer integer = new Integer(i); //tmpList.add(integer); } long em = Runtime.getRuntime().totalMemory(); System.out.println("End Memory :" em); System.out.println("End-Start Memory :" (em - sm)); //walkList(tmpList); System.out.println("<<<<<<<<<<<<<<<>>>>>>>>>>>>>"); long sm = Runtime.getRuntime().totalMemory(); System.out.println("Begin Memory :" sm); Map m = new Hashtable(); LinkedList tmpList = new LinkedList(); for (int i=0;i<1000000;i ) { //m.put("" i,"i=" i); tmpList.add("i=" i); } long em = Runtime.getRuntime().totalMemory(); System.out.println("End Memory :" em); System.out.println("End-Start Memory :" (em - sm)); //walkList(tmpList); System.out.println("<<<<<<<<<<<<<<<
原创粉丝点击