选择显示字体大小

对java 提供的两个map 进行了性能测试,并尝试自己优化

from&nbsp;foxcrane的blog: <a href=&quot;http://www.matrix.org.cn/blog/foxcrane&quot;>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&amp;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(&quot;-----&quot;);<br>test1();<br>}<br>public static void test1(){<br>map m = new hashmap();<br>long t0 = system.currenttimemillis();<br>for (int i = 0; i &lt; 99999 ; i++)<br>{ <br>m.put(&quot;aa.bb.to.pub.&quot;+i+&quot;12345asfsdfvo&quot;,i+&quot;value&quot;);<br>}<br>long t1 = system.currenttimemillis() ;<br>system.out.println(t1-t0);;<br>//system.out.println(m.get(&quot;8888key&quot;));<br>for (int i = 0; i &lt; 99999 ; i++)<br>{<br>m.get(&quot;aa.bb.to.pub.&quot;+i+&quot;12345asfsdfvo&quot;);<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(&quot;aa.bb.ao&quot;,new hashmap());<br>m.put(&quot;aa.bb.do&quot;,new hashmap());<br>m.put(&quot;aa.bb.wo&quot;,new hashmap());<br>m.put(&quot;aa.bb.po&quot;,new hashmap());<br>m.put(&quot;aa.bb.io&quot;,new hashmap());<br>m.put(&quot;aa.bb.oo&quot;,new hashmap());<br>m.put(&quot;aa.bb.bo&quot;,new hashmap());<br>m.put(&quot;aa.bb.to&quot;,new hashmap());<br>m.put(&quot;aa.bb.yo&quot;,new hashmap());<br>m.put(&quot;aa.bb.ro&quot;,new hashmap());<br>long t0 = system.currenttimemillis();<br>for (int i = 10; i &lt; 20 ; i++)<br>{ <br>for (int k = 1; k &lt; 5 ; k++) //有10个模块,比较5个模块概率<br>if(&quot;aa.bb.to.pub.12345headervo&quot;.startswith(&quot;aa.bb.to&quot;));<br>//下面假设上边比较结果为: aa.bb.to开头<br>for(int j = 1000; j &lt; 2000; j++) //每个模块里有1000个<br>((map)m.get(&quot;aa.bb.to&quot;)).put(&quot;aa.bb.to.pub.&quot;+j+&quot;12345asfsdfvo&quot;,&quot;value&quot;);<br>}<br>long t1 = system.currenttimemillis() ;<br>system.out.println(&quot;录入时间为:&quot;+(t1-t0));;<br>//system.out.println(m.get(&quot;8888key&quot;));<br>for (int i = 10; i &lt; 20 ; i++)<br>{ <br>for (int k = 1; k &lt; 5 ; k++) //有10个模块,比较5个模块概率<br>if(&quot;aa.bb.to.pub.12345asfsdfvo&quot;.startswith(&quot;aa.bb.to&quot;));<br><br>for(int j = 1000; j &lt; 2000; j++)<br>((map)m.get(&quot;aa.bb.to&quot;)).get(&quot;aa.bb.to.pub.&quot;+j+&quot;12345asfsdfvo&quot;);<br>}<br>long t2 = system.currenttimemillis() ;<br>system.out.println(&quot;查找时间为:&quot;+(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   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons