/**
* 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/