Running a simple operation like that in parallel adds an overhead to the processor which may mean that it does not actually run faster than a simple sequence. Adding 10,000 integers in sequence will always run quite fast owing to pipelining and other optimised operations.
[edit]
I have just discovered the flaw in your test, you are not comparing like for like. In the first case you are just adding the numbers to get the sum, which is very fast at the processor level. However in your parallel test you are using
Arrays.stream
to convert the array to an
IntStream (Java Platform SE 8 )[
^] object, which adds a considerable overhead. If you change the first loop code to the following it is a much more valid test:
sum=Arrays.stream(arr).sum();
So when I ran that I got the following results:
Sequential time: 18676400
Parallel time: 12258900
I ran a few more tests and the parallel run was always faster.
[/edit]