• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

Streams Performance vs Collection Performance

 
Ranch Hand
Posts: 441
2
Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is it safe to say that for same operations, streams will always have better performance compared to collections? Can you please share your experiences regarding this.
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vaibhav Gargs wrote:Is it safe to say that for same operations, streams will always have better performance compared to collections? Can you please share your experiences regarding this.



Its not clear what you are asking for. Do you have any examples/sample operations to share ?

I googled "java  stream vs collection performance".

I found one link that sounds useful - https://stackoverflow.com/questions/22658322/java-8-performance-of-streams-vs-collections
Another one by Angelika Langer - https://jaxenter.com/java-performance-tutorial-how-fast-are-the-java-8-streams-118830.html

Does that help ?

 
Marshal
Posts: 5003
319
IntelliJ IDE Python Java Linux
  • Likes 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
From my own experience with working with Streams and 'normal' iteration my advice would be to stop worrying about performance. Unless you have quantifiable evidence that a particular piece of iteration in your system is causing a bottleneck then just do whatever you and your colleagues (if in a team) are most comfortable with and move on.
 
Marshal
Posts: 16591
277
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
A big YES to what Tim said.
 
Ranch Hand
Posts: 143
6
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Tim Cooke wrote:From my own experience with working with Streams and 'normal' iteration my advice would be to stop worrying about performance. Unless you have quantifiable evidence that a particular piece of iteration in your system is causing a bottleneck then just do whatever you and your colleagues (if in a team) are most comfortable with and move on.



Hypothetically, a function could be slow because of the stream code in it or some other code in it. How do we find out which of its lines are responsible for the slowness ?
 
Tim Cooke
Marshal
Posts: 5003
319
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How do you know how long anything takes? You measure it.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic