ArrayList vs Vector
I’ve done some more work on the ArrayList vs Vector performance issue. The post below originally stated that Vector would/could outperform ArrayList even though it is synchronized while ArrayList is not. Well, in digging deeper into the issue, I”ve determined that there is a problem with the benchmarking framework being used. I ran a very simple test with ArrayList and Vector to look at performance of add() and contains() methods and have determined that:
ArrayList.add() is 13% faster than Vector.add()
ArrayList.contains() is 3% faster than Vector.contains()
Now I need to identify the problem with the benchmark framework.
I’ve been surprised of late in my Unique Collection Building benchmarks that TreeSet was outperformed by ArrayList. One reason this could happen would be due to the nature of the dataset being processed and the data set I had contained many items with the first 20 characters or so being the same. You know, lots of entries starting with “/WEB-INF/javascript” perhaps. This would have made the TreeSets comparisons in deciding ordering more costly.
So, now I run the test again but with Vector thrown into the mix and the Strings are all 40 characters long and very, very random. The odds of differing after 2 or 3 characters are now very high.
TreeSet should do much better.
But how will Vector fair?
You probably know as well as I do that ArrayList is the faster, unsynchronized option to Vector ( much like using StringBuilder instead of StringBuffer ). But how much faster is ArrayList? Here are the results:

















It would appear, that for java6 on windows xp:
ArrayList.add() is 13% faster than Vector.add()
ArrayList.contains() is 3% faster than Vector.contains()