Java

本类阅读TOP10

·使用MyEclipse开发Struts框架的Hello World!(录像1)
·hibernate配置笔记
·AOP编程入门--Java篇
·linux下Tomcat 5.0.20 与 Apache 2 安装/集成/配置
·在win2003下整合了整合Tomcat5.5+ apache_2.0.53+ mod_jk_2.0.47.dll
·构建Linux下IDE环境--Eclipse篇
·Jsp 连接 mySQL、Oracle 数据库备忘(Windows平台)
·ASP、JSP、PHP 三种技术比较
·Tomcat5.5.9的安装配置
·AWT GUI 设计笔记(二)

分类导航
VC语言Delphi
VB语言ASP
PerlJava
Script数据库
其他语言游戏开发
文件格式网站制作
软件工程.NET开发
HashMap vs FastHashMap

作者:未知 来源:月光软件站 加入时间:2005-2-28 月光软件站

Test Code:

01 import java.util.HashMap;
02 import java.util.Map;
03 
04 import org.apache.commons.collections.FastHashMap;
05 
06 /**
07  <p>HashMapTester.java</p>
08  
09  <p>
10  * <a href="HashMapTester.java.html"><i>View Source</i></a>
11  </p>
12  
13  @author $Author$
14  @version $Reversion$ $Date$
15  */
16 public class HashMapTester {
17 
18     /**
19      
20      */
21     public HashMapTester() {
22         super();
23     }
24     
25     public static void main(String[] args){
26         int N = 50000;
27         long start = System.currentTimeMillis();
28         Map hm = new HashMap(N);
29         for(int i = 0; i < N ; i++){
30             hm.put(new Long(i),"HashMap " + i);
31         }
32         long end = System.currentTimeMillis() - start;
33         System.out.println("HashMap put " + N + " Object using" (end/1000.0"s");
34         start = System.currentTimeMillis();
35         FastHashMap fhm = new FastHashMap(N);
36         //fhm.setFast(false);
37         for(int i = 0; i < N ; i++){
38             fhm.put(new Long(i),"FastHashMap " + i);
39         }
40         end = System.currentTimeMillis() - start;
41         System.out.println("FastHashMap put " + N + " Object using" (end/1000.0"s");
42         
43         
44         start = System.currentTimeMillis();
45         for(int i = 0; i < N ; i++){
46             hm.get(new Long(i));
47         }
48         end = System.currentTimeMillis() - start;
49         System.out.println("HashMap get " + N + " Object using" (end/1000.0"s");
50         fhm.setFast(true);
51         start = System.currentTimeMillis();
52         for(int i = 0; i < N ; i++){
53             fhm.get(new Long(i));
54         }
55         end = System.currentTimeMillis() - start;
56         System.out.println("FastHashMap get " + N + " Object using" (end/1000.0"s");
57         
58     }
59 
60 }

Result:

HashMap put 50000 Object using1.021s
FastHashMap put 50000 Object using1.221s
HashMap get 50000 Object using0.561s
FastHashMap get 50000 Object using0.04s



相关文章

相关软件