Originally posted by Jeroen T Wenting:
Jim, I've timed Vector against ArrayList and found that the same method processing the same dataset (several thousand records) was an order of magnitude faster when using ArrayList than it was using Vector (milliseconds rather than seconds).
I'd hardly call that an insignificant difference.
that depends on a lot of things, including your operating system, which version of the JVM you're running, etc.
Not that I disagree with you. Array list is faster because it doesn't have the overhead of synchronization. However, the point that you are arguing on is one that varies from machine to machine, so while I'm not saying you are wrong, I also feel that Jim is just as correct. It's certainly not so horrendously slow that it would turn a complicated algorithm performed on each element of a list into an massively slow operation. If the algorithm is even slightly complex, the time to perform the computations on each element of the list is so much greater than the access time that the synchronization overhead is essentially negligible. If it takes 200 times as long to perform the calculations as it does to get the access the element of the list, then who cares about a magnitude difference in the access time? You've just increased total run time by, what, 5%, maybe? Is it really that important? Sometimes, yes, sometimes, no.
Furthermore, in my experience, in many (but admittedly not all) cases where you are really concerned about speed of accessing data in a collection, you will want to be using the fastest jvm available, in which case, you don't really have to worry about the synchronization cost (for example, in 1.5, it can almost be ignored in most cases). Also, for situations where you ARE using multithreading, you would have to synchronize your array list as well, so there, the point is basically moot.
Anyway, my vote is for ArrayList, but I wouldn't say that vector is EXTREMELY slower that ArrayList in all, or even most, situations.
- Adam