from foxcrane的blog: <a href="http://www.matrix.org.cn/blog/foxcrane">http://www.matrix.org.cn/blog/foxcrane<br><br></a>
<p>对java 提供的两个map 进行了性能测试<br>发现效果还可以10万个key的map 查找 起来也不是很慢,大概50--60毫秒</p>
<p>还打算自己手工做些性能优化,将不同前缀的key分开到几个小map里 <br>发现性能没有改观,纳闷中。。</p>
<p>分开到几个小map里,然后小的里面还可以再分,分分分,形成一个按字母检索树</p>
<p>突然想起,java pro 上有篇文章里说过map系列的内置 性能优化方式,好象就是和我说的这种思想是一致的</p>
<p>查找资料一看(http://www.fawcette.com/china/xmlfile.aspx?id=8&page=1),过真如此,哈哈,不过上次看了印象不深刻,这次自己想出来了,印象当真深刻的很,同时也证明了英雄所见略同(呵呵)</p>
<p></p>
<p><br>/**<br>* map 系列性能测试<br>*/ <br>import java.util.*;<br>public class maptest<br>{<br>public static void main(string ags[]){<br>test2();<br>system.out.println("-----");<br>test1();<br>}<br>public static void test1(){<br>map m = new hashmap();<br>long t0 = system.currenttimemillis();<br>for (int i = 0; i < 99999 ; i++)<br>{ <br>m.put("aa.bb.to.pub."+i+"12345asfsdfvo",i+"value");<br>}<br>long t1 = system.currenttimemillis() ;<br>system.out.println(t1-t0);;<br>//system.out.println(m.get("8888key"));<br>for (int i = 0; i < 99999 ; i++)<br>{<br>m.get("aa.bb.to.pub."+i+"12345asfsdfvo");<br>}<br>long t2 = system.currenttimemillis() ;<br>system.out.println(t2-t1);<br><br>}<br>public static void test2(){<br>map m = new hashmap();<br>m.put("aa.bb.ao",new hashmap());<br>m.put("aa.bb.do",new hashmap());<br>m.put("aa.bb.wo",new hashmap());<br>m.put("aa.bb.po",new hashmap());<br>m.put("aa.bb.io",new hashmap());<br>m.put("aa.bb.oo",new hashmap());<br>m.put("aa.bb.bo",new hashmap());<br>m.put("aa.bb.to",new hashmap());<br>m.put("aa.bb.yo",new hashmap());<br>m.put("aa.bb.ro",new hashmap());<br>long t0 = system.currenttimemillis();<br>for (int i = 10; i < 20 ; i++)<br>{ <br>for (int k = 1; k < 5 ; k++) //有10个模块,比较5个模块概率<br>if("aa.bb.to.pub.12345headervo".startswith("aa.bb.to"));<br>//下面假设上边比较结果为: aa.bb.to开头<br>for(int j = 1000; j < 2000; j++) //每个模块里有1000个<br>((map)m.get("aa.bb.to")).put("aa.bb.to.pub."+j+"12345asfsdfvo","value");<br>}<br>long t1 = system.currenttimemillis() ;<br>system.out.println("录入时间为:"+(t1-t0));;<br>//system.out.println(m.get("8888key"));<br>for (int i = 10; i < 20 ; i++)<br>{ <br>for (int k = 1; k < 5 ; k++) //有10个模块,比较5个模块概率<br>if("aa.bb.to.pub.12345asfsdfvo".startswith("aa.bb.to"));<br><br>for(int j = 1000; j < 2000; j++)<br>((map)m.get("aa.bb.to")).get("aa.bb.to.pub."+j+"12345asfsdfvo");<br>}<br>long t2 = system.currenttimemillis() ;<br>system.out.println("查找时间为:"+(t2-t1));<br><br>}<br>};</p>
Java Asp PHP .Net XML C/C++ CGI VB Jsp J2ee J2se J2me EJB Servlet Tomcat Resin Struts Weblogic Eclipse ANT GUI JMS Web servise IDEA Webphere Hibernate Spring Jboss Applet Swing Socket Javamail Perl Ajax P2P 安全 模式 框架 测试 开源 游戏
Windows XP Windows 2000 Windows 2003 Windows Me Windows 9.x Linux UNIX 注册表 操作系统 服务器 应用服务器