I am running a very big for loop with 10 million iterations. When I do this in one go it takes 14 secs while when I break it into 20 iterations of 500k small iterations it takes only 6 secs. I am not able to understand why is there such behavior. Is there any problem with my code? Thanks!
Code
public class Benchmark {
static int max = 10000000;
static int start = 0;
static int end = 0;
static boolean dnc = false;
public static void main(String[] args) {
    TimeIt timer = new TimeIt();
    timer.printTime("bmTimer dnc false", () -> bmTimer());
    dnc = true;
    sum = 0;
    timer.printTime("bmTimer dnc true", () -> bmTimer());
}
private static void bmTimer() {
    if (dnc) {
        int factor = 500000;
        for (int i = 0; i < max; i += factor) {
            end = start + factor;
            bm(start, end);
            start = end + 1;
        }
    } else {
        bm(0, max);
    }
}
static int sum = 0;
private static void bm(int start, int end) {
    try {
        ExecutorService executor = Executors.newFixedThreadPool(4);
        List<Future<String>> futures = new ArrayList<>();
        for (int j = start; j < end; j++) {
            futures.add(executor.submit(new Callable<String>() {
                @Override
                public String call() throws Exception {
                    int i = 10;
                    int j = 9;
                    return (i - j) + "";
                }
            }));
        }
        for (Future<String> future : futures) {
            sum += Integer.parseInt(future.get());
        }
        System.out.println(sum);
        executor.shutdown();
        executor.awaitTermination(1, TimeUnit.DAYS);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Output
10000000
Method bmTimer dnc false took : 14.39s
500000
1000000
1500000
2000000
2500000
3000000
3500000
4000000
4500000
5000000
5500000
6000000
6500000
7000000
7500000
8000000
8500000
9000000
9500000
10000000
Method bmTimer dnc true took : 5.856s
