import java.util.*;
public class Test3
{
static int MAP_SIZE = 1000000;
static Integer[] positives = new Integer[MAP_SIZE];
static Integer[] negatives = new Integer[MAP_SIZE];
static
{
for (int i = 1; i < MAP_SIZE; i++)
{
positives[i] = new Integer(i);
negatives[i] = new Integer(-i);
}
}
static void populate(Map m)
{
populate(m, MAP_SIZE);
}
static void populate(Map m, int size)
{
for (int i = 1; i < size; i++)
m.put(positives[i], negatives[i]);
}
public static void main(String[] args)
{
test1(false, 0.75f);
test1(true, 0.75f);
test1(false, 0.75f);
test1(true, 0.75f);
test1(false, 0.75f);
test1(true, 0.75f);
test1(false, 0.5f);
test1(true, 0.5f);
test1(false, 0.5f);
test1(true, 0.5f);
test1(false, 0.5f);
test1(true, 0.5f);
}
static void test1(boolean presize, float loadfactor)
{
Map m;
if (presize)
m = new HashMap((MAP_SIZE*2)+1, loadfactor);
else
m = new HashMap();
long start = System.currentTimeMillis();
populate(m);
long end = System.currentTimeMillis();
System.out.println("Time to populate with presize: " + presize + " is " + (end-start) +
" (ms) with " + m.getClass().getName());
System.gc();
try{Thread.sleep(1000);}catch(InterruptedException e){}
System.gc();
try{Thread.sleep(1000);}catch(InterruptedException e){}
}
}
|