public class Test {
public static void main(String[] args) {
int x = 150_000;
long start = System.currentTimeMillis();
for(int i = 0; i < x; i++) {
f1(i);
}
long end = System.currentTimeMillis();
System.out.println((end - start) / 1000.0);
}
private static long f1(int n) {
long x = 1;
for(int i = 0; i < n; i++) {
x = x + x;
}
return x;
}
}
Can someone explain why setting x to 150_000
or 4_000_000
or even 2_000_000_000
doesn't change execution time of this loop?