Win a copy of Rust Web Development this week in the Other Languages 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

performance : arraylist vs vector

 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is vector slow as compared to arraylist even in single threaded environment ?
if it is , then why?
 
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vector is slow than ArrayList because method of vector are synchronized and that of ArrayList are not
 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pramod P Deore wrote:Vector is slow than ArrayList because method of vector are synchronized and that of ArrayList are not



but how does it matter in a single threaded environment ?
Does calling a synchronized method take more time than non-synchronized method??? please explain
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If program runs in single threaded environment then time required for calling a synchronized method non-synchronized method is same. Because of synchronized method only one thread can execute that method at a time, but in single thread environment there is only one thread so time required is also same.
 
anish jain
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Pramod P Deore wrote:If program runs in single threaded environment then time required for calling a synchronized method non-synchronized method is same. Because of synchronized method only one thread can execute that method at a time, but in single thread environment there is only one thread so time required is also same.



so it means that in single threaded environment both arraylist and vector will yiel same performance
am i right?
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

in single threaded environment both arraylist and vector will yiel same performance
am i right?



Yes. Hello Ranchers please correct me if I am wrong
 
author and iconoclast
Posts: 24203
44
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're wrong There's a small overhead associated with calling a synchronized method; that small overhead is exactly the same regardless of how many threads there might be in a program (note that all Java programs are multithreaded, because even if you only write code in one thread, the JVM supplies many other threads of its own.) For this reason, in any program, the methods of Vector will be a tiny bit slower than those of ArrayList. But only a tiny bit.

A larger difference comes from the different rescaling algorithms they use -- ArrayList grows in smaller increments, and is generally more efficient.
 
Pramod P Deore
Ranch Hand
Posts: 633
Android Eclipse IDE Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ernest Friedman-Hill for correcting me, I really forgot the thing that the JVM supplies many other threads of its own.
 
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