4 ms·
I would question these results. I ran the same code on a more modern processor (i7-3930K) for 1000000000 iterations and got these averages over 10 loops after a
by speakeron 11y ago
I would question these results. I ran the same code on a more modern processor (i7-3930K) for 1000000000 iterations and got these averages over 10 loops after a warm-up:
Array: 453 ms
Stream: 887 ms
Parallel stream: 120 ms
The array loop code is about twice as fast as the sequential stream (parallel stream blows both of them away). The array loop advantage will start to go away once you increase the complexities of what you're doing in the loop and, of course, the stream code is much more readable.
(Edit: I also tested IntStream().of() instead Array().stream() for the sequential stream test, the results were identical in both cases.)