public class Test2
{
public static void main(String[] args)
{
checkPooling(false);
checkPooling(true);
checkPooling(false);
checkPooling(true);
}
private static void checkPooling(boolean pooling)
{
long time = System.currentTimeMillis();
int k = 0;
for (int i = 0; i < 300000000; i++)
{
if (pooling)
{
k += Integer.valueOf(2).intValue();
}
else
{
k += new Integer(2).intValue();
}
}
System.out.println("Time: " + (System.currentTimeMillis() - time));
}
}
public class Test3
{
public static void main(String[] args)
{
checkPooling(false);
checkPooling(true);
checkPooling(false);
checkPooling(true);
}
private static void checkPooling(boolean pooling)
{
long time = System.currentTimeMillis();
int k = 0;
for (int i = 0; i < 300000000; i++)
{
if (pooling)
{
k += Integer.valueOf(222).intValue();
}
else
{
k += new Integer(222).intValue();
}
}
System.out.println("Time: " + (System.currentTimeMillis() - time));
}
}
public static Integer valueOf(int i) {
final int offset = 128;
if (i >= -128 && i <= 127) { // must cache
return IntegerCache.cache[i + offset];
}
return new Integer(i);
}