I want to test the time of adding and getting item in simple and generic hashmap:
public void TestHashGeneric(){
        Map hashsimple = new HashMap();             
        long startTime = System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            hashsimple.put("key"+i, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" );
        }
        for (int i = 0; i < 100000; i++) {
            String ret =(String)hashsimple.get("key"+i);
        }
        long endTime =System.currentTimeMillis();
        System.out.println("Hash Time " + (endTime - startTime) + " millisec");
        Map<String,String> hm = new HashMap<String,String>();
        startTime =  System.currentTimeMillis();
        for (int i = 0; i < 100000; i++) {
            hm.put("key"+i, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" );
        }
        for (int i = 0; i < 100000; i++) {
            String ret = hm.get("key"+i);
        }
        endTime = System.currentTimeMillis();
        System.out.println("Hash generic Time " + (endTime - startTime) + " millisec");         
    }
The problem is that I get different time if I change places between hashmap's code section! if i put the loops (with the time print ofcourse) of generic below the simple I get better time for generic and if i put simple below the generic I get better time for simple!
Same happens if I use different methods for this.
 
     
     
     
    