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?