Monday, July 5, 2010

Hashtable vs. HashMap and a little thing called Entry -Part2

69
70 /**
71 * Hashtable perf.
72 */
73 private static void hashtablePerf() {
74 // Hashtable
75 map = new Hashtable<>();
76 start = System.currentTimeMillis();
77 for (int i = 0; i <>
78 map.put(bob + i, bob);
79 }
80 end = System.currentTimeMillis();
81 System.out.println("Inserting Hashtable: " + (end - start) + " ms");
82
83 start = System.currentTimeMillis();
84 for (int i = 0; i <>
85 map.get(bob + i);
86 }
87 end = System.currentTimeMillis();
88 System.out.println("Reading Hashtable: " + (end - start) + " ms");
89
90 start = System.currentTimeMillis();
91 for(Entry<> e : map.entrySet()){
92 String val = e.getValue();
93 }
94 end = System.currentTimeMillis();
95 System.out.println("Reading Hashtable by Entry: " + (end - start) + " ms");
96
97 }
98
99}
Output:
Inserting Hashtable: 640 ms
Reading Hashtable: 172 ms
Reading Hashtable by Entry: 31 ms
Inserting HashMap: 610 ms - Synchronized: false
Reading HashMap: 265 ms - Synchronized: false
Reading HashMap by Entry: 47 - Synchronized: false
Inserting HashMap: 625 ms - Synchronized: true
Reading HashMap: 282 ms - Synchronized: true
Reading HashMap by Entry: 46 - Synchronized: true

No comments:

Post a Comment