• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Junilu Lacar
  • Tim Cooke
Saloon Keepers:
  • Carey Brown
  • Stephan van Hulst
  • Tim Holloway
  • Peter Rooke
  • Himai Minh
Bartenders:
  • Piet Souris
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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...

 
Marshal
Posts: 77957
373
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I suspect the acceleration on subsequent runs may be caused by just in time compilation.
 
Campbell Ritchie
Marshal
Posts: 77957
373
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
… but my suspicion may be incorrect.
 
Bartender
Posts: 2236
63
IntelliJ IDE Firefox Browser Spring Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 1871
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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!
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic