(re-sent with previous emails trimmed to reduce size)
Kevin,
The difference is the use of invokeInterface vs invokeVirtual.
Now, as to why those two differ so much, you'd have to ask the VM
compiler guys.
David Holmes
Kevin L. Stern said the following on 05/09/10 23:14:
Trying to understand this:
public static void main(String[] args) {
final NumberFormat format = new DecimalFormat("0.000000");
final Random rng = new Random();
final int maxSize = 100000;
final int warmup = 100;
final long[] time = new long[2];
for (int i = 0; i < 1000; i++) {
if (i % 3 == 0)
System.gc();
List<Integer> cad = new ChunkedArrayDeque<Integer>();
List<Integer> al = new ArrayList<Integer>(1);
int size = rng.nextInt(maxSize - 1) + 1;
long thisTime = System.nanoTime();
for (int j = 0; j < size; j++) {
al.add(j);
}
if (i > warmup)
time[0] += System.nanoTime() - thisTime;
thisTime = System.nanoTime();
for (int j = 0; j < size; j++) {
cad.add(j);
}
if (i > warmup)
time[1] += System.nanoTime() - thisTime;
}
System.out.println(format.format((double)time[1] / time[0]));
}
Consistently prints around 0.834112, whereas if I change
List<Integer> al = new ArrayList<Integer>(1);
to
ArrayList<Integer> al = new ArrayList<Integer>(1);
I consistently see around 0.965947.
Any ideas why the type of the reference would make such a difference?
Kevin