4 ms·
I'm in agreement with the first few comments already - at least some parts of this advice is dubious. For one - some performance examples (specifically, intege
by zinxq 11y ago
I'm in agreement with the first few comments already - at least some parts of this advice is dubious.
For one - some performance examples (specifically, integer array iteration) is 15 times slower with streams.
Angelika Langer's analysis:
https://jaxenter.com/java-performance-tutorial-how-fast-are-the-java-8-streams-118830.html https://jaxenter.com/java-performance-tutorial-how-fast-are-...
- coldtea 11y ago>For one - some performance examples (specifically, integer array iteration) is 15 times slower with streams. That's a very misleading example, and even the linked post itself explains why it is so (e.g. not much is done with the integers in the first place).
- speakeron 11y agoI 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.)