It’s not only “it’s not possible to write a test test for each cycle”, but its counter is effective. The specific circuit specific to the application may be completely different when it is introduced into the micro benchmark.
For a real application, the standard optimization rule applies: do not do this. Just write what is more readable, and only if there is a performance problem, profile the entire application to see if a particular loop or streaming usage is really a bottleneck. Only if this is the case, can you try switching between idioms in a particular bottleneck to see if the difference matters.
In most cases, it will not. If there is a real performance issue, it will be related to the type of operation, for example. performing a nested iteration with a time complexity of O(n²) , etc. Such issues are independent of whether you use a Stream or for loop, and slight performance differences between the two idioms do not change how your code scales.
source share