Hashtable Vs Hashmap
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   sudhakar_chavali
Posted On:   Sunday, August 29, 2004 08:43 AM

When comparing Hashtable and Hashmap, I am always getting Hashtable is faster than Hashmap I was under impression that, Hashmap is faster than Hashtable becuase Hashmap is unsynchronized. So I would like to know ur experiences, or do u know any benchmark performance tests related to this??. Here is my test code On Windows XP- P4 1.2 Ghz and Jdk 1.4 import java.util.*; public class HashTest {    public static void main(String s[])    {     for(int k=0;k <10;k++)     {      int i=0;    More>>




When comparing Hashtable and Hashmap, I am always getting Hashtable is faster than Hashmap



I was under impression that, Hashmap is faster than Hashtable becuase Hashmap is unsynchronized.



So I would like to know ur experiences, or do u know any benchmark performance tests related to this??.






Here is my test code



On Windows XP- P4 1.2 Ghz and Jdk 1.4



import java.util.*;

public class HashTest

{

   public static void main(String s[])

   {

    for(int k=0;k <10;k++)

    {

     int i=0;

     Date start=new Date();

     Hashtable ht=new Hashtable();

     for( i=0;i <100000;i++)

     {

     Integer ii=new Integer(i);

     ht.put(ii,ii);

     }

     ht=null;

     Date end=new Date();

     System.err.println("Hashtable Time for putting key value pairs :"+(end.getTime()-start.getTime()));



     start=new Date();


    HashMap hm=new HashMap();


     for( i=0;i <100000;i++)

     {

     Integer ii=new Integer(i);

     hm.put(ii,ii);


     }

     hm=null;

     end=new Date();

     System.err.println("Hashmap Time for putting key value pairs :"+(end.getTime()-start.getTime()));


     }



     }


   }











Hashtable Time for putting key value pairs :235

Hashmap Time for putting key value pairs :359

Hashtable Time for putting key value pairs :187

Hashmap Time for putting key value pairs :328

Hashtable Time for putting key value pairs :188

Hashmap Time for putting key value pairs :328

Hashtable Time for putting key value pairs :187

Hashmap Time for putting key value pairs :344

Hashtable Time for putting key value pairs :188

Hashmap Time for putting key value pairs :343

Hashtable Time for putting key value pairs :188

Hashmap Time for putting key value pairs :359

Hashtable Time for putting key value pairs :203

Hashmap Time for putting key value pairs :328

Hashtable Time for putting key value pairs :204

Hashmap Time for putting key value pairs :343

Hashtable Time for putting key value pairs :188

Hashmap Time for putting key value pairs :344

Hashtable Time for putting key value pairs :187

Hashmap Time for putting key value pairs :328




Thanks


Sudhakar

   <<Less

Re: Hashtable Vs Hashmap

Posted By:   Krishna_Adavi  
Posted On:   Tuesday, August 31, 2004 10:10 AM

Hashtable is faster when filling. Hashmap is faster in iteration and removing. See if this helps.

http://www.java-performance-portal.org/modules.php?name=News&file=article&sid=18
About | Sitemap | Contact