performance - Insert Speed Compare HashMap, LinkedHashMap -


trying compare speed of insertion between hashmap , linkedhashmap found smaller no of objects until 100000 objects speed faster hashmap. when set insertion count 500000 speed faster linkedhashmap. please use code connected verify scenario. throw light on why speed comparision gets reversed.

below class hashmaptest:

import java.util.hashmap; import java.util.linkedhashmap;  public class hashmaptest {  public static void main(string args[]) {    final int count = 100000;    // create hash map   hashmap<string, comparable> hm = new hashmap();   linkedhashmap<string, comparable> lhm = new linkedhashmap();    // put elements map    long starttime = system.nanotime();        (int = 0; < count; i++){       hm.put("obj" + i, new string("" + i));   }       long estimatedtime = system.nanotime() - starttime;   system.out.println("\n time taken insert " + count + " objects (hashmap)= " + estimatedtime / 1000000 + " milliseconds" );     starttime = system.nanotime();      (int = 0; < count; i++){     lhm.put("obj" + i, new string("" + i)); }         long estimatedtimelinked = system.nanotime() - starttime;    system.out.println("\n time taken insert " + count + " objects (linkedhashmap)= " + estimatedtimelinked / 1000000 + " milliseconds" );    system.out.println("\n difference between linked , normal " + (estimatedtimelinked - estimatedtime) / 1000000 + " milliseconds" );     /*  set set = hm.entryset();   iterator = set.iterator();    // display elements   while(i.hasnext()) {      map.entry me = (map.entry)i.next();     // system.out.print(me.getkey() + ": ");    //  system.out.println(me.getvalue());   }*/  } 

}


Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -