/**
* 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));
}
};