I am wondering why it takes so much longer to run a loop with a long index vs. an integer index?
Any idea?
Thanks
int n = 1000_000_000;
long n2 =n;
long t1 = System.currentTimeMillis();
for( int idx = 0; idx<n;idx++){
}
long t2 = System.currentTimeMillis();
for( long idx = 0; idx<n2;idx++){
}
long t3 = System.currentTimeMillis();
long dt1 = t2-t1;
long dt2 = t3-t2;
System.out.println("with int = took " + dt1 +"ms");
System.out.println("with long = took " + dt2 +"ms");