• Post Reply Bookmark Topic Watch Topic
  • New Topic

java streams supposed to be better performance, but my test says otherwise.  RSS feed

 
Warren Goldman
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The test case shows streams approach to filter then sort is much slower on first call, seems to speed up on second and third, but the old way of sorting and filtering seems to be quicker.

Can anyone explain this?

Here are the results:
new:49 count: 2500
old:4 count: 2500
new:2 count: 2500
old:2 count: 2500
new:1 count: 2500

Files with the extension .java are not allowed as attachment in the message... so here is the code...

 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect the acceleration on subsequent runs may be caused by just in time compilation.
 
Campbell Ritchie
Sheriff
Posts: 53779
128
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
… but my suspicion may be incorrect.
 
Paweł Baczyński
Bartender
Posts: 1998
42
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Warren Goldman wrote:Files with the extension .java are not allowed as attachment in the message... so here is the code...

Actually you should put your code inside [code] tags like you just did.
You can read more about those here: UseCodeTags (click)
 
Rahul Mahindrakar
Ranch Hand
Posts: 1869
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

The only thing I can see is that the lack of usage of parallelStream()

--
java.util.List newRedsSorted = allApples.parallelStream()
--

But when I changed it still no change in result.

Intresting problem!
 
Mohamed Sanaulla
Bartender
Posts: 3169
34
Google App Engine Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This discussion should be of help where a similar experiment of using Collections API and Stream API was used for sorting of Integers.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!