對java 提供的兩個Map 進行了性能測試發現效果還可以
還打算自己手工做些性能優化
分開到幾個小MAP裡
突然想起
查找資料一看(x?ID=
/**
* Map 系列性能測試
*/
import java
public class MapTest
{
public static void main(String ags[]){
test
System
test
}
public static void test
Map m = new HashMap();
long t
for (int 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));
}
};
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19175.html