I have a simple below program which iterates through an array
Integer [] intArray = new Integer[20000];
int index=0;
for(int i=10000; i>=0; i--){
intArray[index]=i;
index++;
}
long startTime = System.currentTimeMillis();
for(Integer t : intArray){
System.out.println(t);
}
long endTime = System.currentTimeMillis();
long consumedTime = endTime-startTime;
System.out.println("Consumed time "+ consumedTime);
I always get different values of consumed time like 743, 790, 738, 825, 678.
Why time taken by for loop is always different for each execution.
Note I am running this code inside a main method. My OS is Ubuntu and processor is 32 bit.