KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > tests > HashMapTest


1 package org.jgroups.tests;
2
3 //import gnu.trove.TLongObjectHashMap;
4
//import gnu.trove.THashMap;
5

6 import java.util.HashMap JavaDoc;
7 import java.util.Map JavaDoc;
8 import java.util.TreeMap JavaDoc;
9
10 /**
11  * @author Bela Ban
12  * @version $Id: HashMapTest.java,v 1.1 2005/04/14 04:49:32 belaban Exp $
13  */

14 public class HashMapTest {
15
16
17     public static void main(String JavaDoc[] args) {
18         int num=10000;
19         for(int i=0; i < args.length; i++) {
20             if(args[i].equals("-num")) {
21                 num=Integer.parseInt(args[++i]);
22                 continue;
23             }
24             System.out.println("HashMapTest [-num <num>] [-help]");
25         }
26         HashMapTest t=new HashMapTest();
27         t.start(new HashMap JavaDoc(), num);
28         t.start(new TreeMap JavaDoc(), num);
29         //t.start2(new TLongObjectHashMap(), num);
30
//t.start3(new THashMap(), num);
31
System.out.println("");
32         t.start(new HashMap JavaDoc(), num);
33         t.start(new TreeMap JavaDoc(), num);
34         //t.start2(new TLongObjectHashMap(), num);
35
//t.start3(new THashMap(), num);
36
}
37
38    /* private void start3(THashMap m, int num) {
39         long start, stop;
40
41         start=System.currentTimeMillis();
42         for(int i=0; i < num; i++) {
43             m.put(new Long(i), "bla");
44         }
45
46         stop=System.currentTimeMillis();
47         System.out.println("Took " + (stop-start) + "ms to insert " + m.size() + " elements into " + m.getClass().getName());
48         m.clear();
49     }
50
51     private void start2(TLongObjectHashMap m, int num) {
52         long start, stop;
53
54         start=System.currentTimeMillis();
55         for(int i=0; i < num; i++) {
56             m.put(i, "bla");
57         }
58
59         stop=System.currentTimeMillis();
60         System.out.println("Took " + (stop-start) + "ms to insert " + m.size() + " elements into " + m.getClass().getName());
61         m.clear();
62     }*/

63
64     private void start(Map JavaDoc m, int num) {
65         long start, stop;
66
67         start=System.currentTimeMillis();
68         for(int i=0; i < num; i++) {
69             m.put(new Long JavaDoc(i), "bla");
70         }
71
72         stop=System.currentTimeMillis();
73         System.out.println("Took " + (stop-start) + "ms to insert " + m.size() + " elements into " + m.getClass().getName());
74         m.clear();
75     }
76 }
77
Popular Tags