/* package whatever; // don't place package name! */
import java.util.*;
import java.lang.*;
import java.io.*;
/* Name of the class has to be "Main" only if the class is public. */
class Ideone
{
{
HashMap
<String,Integer
> stringHashMap
= new HashMap
<String,Integer
>();
int iterations = 1000000;
//int
long ti
= System.
currentTimeMillis(); for(int i=0;i<iterations;i++)
{
intHashMap.
put(Integer.
valueOf(i
),i
); ///Integer.valueOf() used to offset the speed implications of String.valueOf() }
System.
out.
println("int put: " + (System.
currentTimeMillis()-ti
));
ti
= System.
currentTimeMillis(); for(int i=0;i<iterations;i++)
{
intHashMap.
get(Integer.
valueOf(i
)); }
System.
out.
println("int get: " + (System.
currentTimeMillis()-ti
));
//String
ti
= System.
currentTimeMillis(); for(int i=0;i<iterations;i++)
{
stringHashMap.
put(String.
valueOf(i
),i
); }
System.
out.
println("string put: " + (System.
currentTimeMillis()-ti
));
ti
= System.
currentTimeMillis(); for(int i=0;i<iterations;i++)
{
stringHashMap.
get(String.
valueOf(i
)); }
System.
out.
println("string get: " + (System.
currentTimeMillis()-ti
));
intHashMap.clear();
stringHashMap.clear();
HashMap
<String,Integer
> stringHashMap2
= new HashMap
<String,Integer
>(); HashMap
<Integer,Integer
> intHashMap2
= new HashMap
<Integer,Integer
>();
//String
ti
= System.
currentTimeMillis(); for(int i=0;i<iterations;i++)
{
stringHashMap2.
put(String.
valueOf(i
),i
); }
System.
out.
println("string put: " + (System.
currentTimeMillis()-ti
));
ti
= System.
currentTimeMillis(); for(int i=0;i<iterations;i++)
{
stringHashMap2.
get(String.
valueOf(i
)); }
System.
out.
println("string get: " + (System.
currentTimeMillis()-ti
));
//int
ti
= System.
currentTimeMillis(); for(int i=0;i<iterations;i++)
{
intHashMap2.
put(Integer.
valueOf(i
),i
); }
System.
out.
println("int put: " + (System.
currentTimeMillis()-ti
));
ti
= System.
currentTimeMillis(); for(int i=0;i<iterations;i++)
{
intHashMap2.
get(Integer.
valueOf(i
)); }
System.
out.
println("int get: " + (System.
currentTimeMillis()-ti
));
}
}
LyogcG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