Win a copy of Testing JavaScript Applications this week in the HTML Pages with CSS and JavaScript forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Streams Performance vs Collection Performance

 
Ranch Hand
Posts: 431
2
Java
  • Mark post as helpful
  • send pies
  • 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
  • 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 ?

 
Sheriff
Posts: 4870
317
IntelliJ IDE Python Java Linux
  • Likes 6
  • Mark post as helpful
  • send pies
  • 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.
 
Sheriff
Posts: 15801
264
Mac Android IntelliJ IDE Eclipse IDE Spring Debian Java Ubuntu Linux
  • Likes 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A big YES to what Tim said.
 
Ranch Hand
Posts: 143
5
IntelliJ IDE Eclipse IDE Java
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 4870
317
IntelliJ IDE Python Java Linux
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do you know how long anything takes? You measure it.
 
sunglasses are a type of coolness prosthetic. Check out the sunglasses on 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
    Bookmark Topic Watch Topic
  • New Topic