I have two piece of code, and I want to know which is faster when they run and why it's faster. I learn less about JVM and CPU, but I'm hard working on them. Every tip will help.
int[] a=new int[1000]; int[] b=new int[10000000]; long start = System.currentTimeMillis(); //method 1 for(int i=0;i<1000;i++){ for(int j=0;j<10000000;j++){ a[i]++; } } long end = System.currentTimeMillis(); System.out.println(end-start); start=System.currentTimeMillis(); //method 2 for(int i=0 ;i<10000000;i++){ for(int j=0;j<1000;j++){ b[i]++; } } end = System.currentTimeMillis(); System.out.println(end-start);
(10000000*1000)