• 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

Vector vs LinkedHashSet iteration speed

 
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
According to Devaka, Practice Exam 3, Question 60, LinkedHashSet has a faster iteration speed than Vector. I don't think you can compare these two for iteration speed however. While it is true that Vector has synchronized methods, which are a disadvantage in terms of performance, it can iterate by sequential indexing, whereas LinkedHashSet would need to iterate by following the links through reference access, which I think could be slower. Any ideas?
 
Bartender
Posts: 6663
5
MyEclipse IDE Firefox Browser Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The Vector is probably at a disadvantage because its methods are synchronized. I gave this a try with a program and the iteration speed is marginally better for the linked hash set.



Result


Time taken to populate: 2344
Time taken to populate: 203
Time taken to iterate: 78
Time taken to iterate: 141
1000000 1000000

 
Ranch Hand
Posts: 86
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi deepak,
nice explanation!
 
Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@Deepak
That was a good explanation...
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Deepu,

nice example
 
Ruben Soto
Ranch Hand
Posts: 1032
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Deepak Bala wrote:The Vector is probably at a disadvantage because its methods are synchronized. I gave this a try with a program and the iteration speed is marginally better for the linked hash set.


Thanks a lot, Deepak. Great example! I think using a practical example is the only way to see which one is faster, because there is no qualitative theoretical principle that dictates one will be faster than the other (whereas, for example, a LinkedHashSet will always have faster iteration than a HashSet, and a HashMap will have faster iteration than a Hashtable, for theoretical reasons.)

Again, great example!
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic