I made the following code.
@Test
public void parallelStream() {
IntStream.rangeClosed(0,10_000).boxed().parallel()
.forEach(System.out::println);
}
@Test
public void parallelStreamOrdered() {
IntStream.rangeClosed(0,10_000).boxed().parallel()
.forEachOrdered(System.out::println);
}
As a result of the performance, parallelStream took 178 ms and parallelStreamOrder took 33 ms.
I know that in parallel, .forEach() is non-deterministic, and .forEachOrdered() is guaranteed order.
But is it related to speed? It was expected that keeping the order would slow down the speed. I wonder why the speed is so different.