• <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>
  • 對java提供的兩個Map進行性能測試

    發表于:2008-05-12來源:作者:點擊數: 標簽:性能測試javaJAVAJavaMap
    對 java 提供的兩個Map 進行了 性能測試 發現效果還可以10萬個key的Map 查找 起來也不是很慢,大概50--60毫秒還打算自己手工做些性能優化,將不同前綴的KEY分開到幾個小MAP里發現性能沒有改觀,納悶中。 分開到幾個小MAP里,然后小的里面還可以再分,分分分,
    java 提供的兩個Map 進行了性能測試發現效果還可以10萬個key的Map 查找 起來也不是很慢,大概50--60毫秒還打算自己手工做些性能優化,將不同前綴的KEY分開到幾個小MAP里發現性能沒有改觀,納悶中。 分開到幾個小MAP里,然后小的里面還可以再分,分分分,形成一個按字母檢索樹突然想起,Java Pro 上有篇文章里說過Map系列的內置 性能優化方式,好象就是和我說的這種思想是一致的 查找資料一看(http://www.fawcette.com/china/XmlFile.aspx?ID=8&page=1),過真如此,哈哈,不過上次看了印象不深刻,這次自己想出來了,印象當真深刻的很,同時也證明了英雄所見略同

    /**
    * Map 系列性能測試
    */
    import java.util.*;
    public class MapTest
    {
    public static void main(String ags[]){
    test2();
    System.out.println("-----");
    test1();
    }
    public static void test1(){
    Map m = new HashMap();
    long t0 = System.currentTimeMillis();
    for (int i = 0; i < 99999 ; i++)
    {
    m.put("aa.bb.to.pub."+i+"12345asfsdfVO",i+"value");
    }
    long t1 = System.currentTimeMillis() ;
    System.out.println(t1-t0);;
    //System.out.println(m.get("8888key"));
    for (int i = 0; i < 99999 ; i++)
    {
    m.get("aa.bb.to.pub."+i+"12345asfsdfVO");
    }
    long t2 = System.currentTimeMillis() ;
    System.out.println(t2-t1);

    }
    public static void test2(){
    Map m = new HashMap();
    m.put("aa.bb.ao",new HashMap());
    m.put("aa.bb.do",new HashMap());
    m.put("aa.bb.wo",new HashMap());
    m.put("aa.bb.po",new HashMap());
    m.put("aa.bb.io",new HashMap());
    m.put("aa.bb.oo",new HashMap());
    m.put("aa.bb.bo",new HashMap());
    m.put("aa.bb.to",new HashMap());
    m.put("aa.bb.yo",new HashMap());
    m.put("aa.bb.ro",new HashMap());
    long t0 = System.currentTimeMillis();
    for (int i = 10; i < 20 ; i++)
    {
    for (int k = 1; k < 5 ; k++) //有10個模塊,比較5個模塊概率
    if("aa.bb.to.pub.12345headerVO".startsWith("aa.bb.to"));
    //下面假設上邊比較結果為: aa.bb.to開頭
    for(int j = 1000; j < 2000; j++) //每個模塊里有1000個
    ((Map)m.get("aa.bb.to")).put("aa.bb.to.pub."+j+"12345asfsdfVO","value");
    }
    long t1 = System.currentTimeMillis() ;
    System.out.println("錄入時間為:"+(t1-t0));;
    //System.out.println(m.get("8888key"));
    for (int i = 10; i < 20 ; i++)
    {
    for (int k = 1; k < 5 ; k++) //有10個模塊,比較5個模塊概率
    if("aa.bb.to.pub.12345asfsdfVO".startsWith("aa.bb.to"));

    for(int j = 1000; j < 2000; j++)
    ((Map)m.get("aa.bb.to")).get("aa.bb.to.pub."+j+"12345asfsdfVO");
    }
    long t2 = System.currentTimeMillis() ;
    System.out.println("查找時間為:"+(t2-t1));

    }
    };

    原文轉自:http://www.kjueaiud.com

    老湿亚洲永久精品ww47香蕉图片_日韩欧美中文字幕北美法律_国产AV永久无码天堂影院_久久婷婷综合色丁香五月

  • <ruby id="5koa6"></ruby>
    <ruby id="5koa6"><option id="5koa6"><thead id="5koa6"></thead></option></ruby>

    <progress id="5koa6"></progress>

  • <strong id="5koa6"></strong>