dimanche 1 mars 2015

Why tests in Java each time goes faster?

I have a little question about Java optimization. I have a code:



import java.util.LinkedList;
import java.util.List;

public class Test {
public static void main(String[] args) {
int testCount = 1_000_000;

test(testCount);
test(testCount);
test(testCount);
}

public static void test(int test) {
List list = new LinkedList();
long start = System.currentTimeMillis();
for (int i = 0; i< test; i++) {
list.add(0, i);
}
long finish = System.currentTimeMillis();
System.out.println("time " + (finish-start));
}
}


Each next iteration of this test much less than previous.



time 2443
time 924
time 143


Could you help me to understand why does it happen?


Aucun commentaire:

Enregistrer un commentaire