Performance Problem

In addition to the correct observation of @darksnake: Output the sum. The JIT compiler is very aggressive and if it sees that the value calculated inside the loop is not used after the loop, it may eliminate the whole loop, eliminate the statement in the loop, or make some other optimization. By outputting the sum, you are doing something productive that the JIT compiler cannot eliminate.

Microbenchmarking is very tricky. If you want to have meaningful results, you must learn how to use JMH (Java Microbenchmark Harness).