Mike Simmons wrote:That's such a small time, it's unlikely the test is very meaningful. The test is too short for the JVM to properly optimize the code. Try repeating the loop a bunch of times to see what happens over longer times. Also try reversing the order that you run the two tests. Does it make a difference?
If the difference does hold up, there are a few possibilities:
How many processors does your machine have? If it's only one, there is no reason to expect any improvement here from parallelStream().
There is probably a little extra overhead in setting up the Stream objects in the first place, and in setting up parallel threads. If you don't give them a big enough job to do, it's not worthwhile.