5 comments

[ 3.2 ms ] story [ 19.4 ms ] thread
I learned only about two things in my numeric methods class that I remember as useful.

Sort before adding tiny values.

Java 3.326788s, C++ 8.46879s on my machine. This is interesting. Code seems analogous.
Code in the question is a bad test example. As the answer shows, different compilers can optimize the code in different ways to make the outer loop almost meaningless. A better test would have 100000 different arrays to test.

Did you enable optimizations in C++ and disable adaptive optimization in java?