Just another dumb microbenchmark Vector vs. ArrayList

If you think to hear something new … don’t wast your time reading this post :wink:

Just because I was interrested I tried the well-known ArrayLIst vs. Vector on a 4-way Power5 machine and it turned out that all the guys claming Vector is faster are fooled by the different resizing characteristics.
It did not more than adding 20.000.000 times the same string object to an initialized collection.

The Collections were created on own Thread so absolutly no contended locking:

Vector:
1 Thread: 2302ms/calculation
10 Threads 2151ms/calculation
50 Threads 2127ms/calc

ArrayList:
1 Thread: 2034ms/calc
10 Threads: 646ms/calc
50 Threads: 524ms/calc

as you can see, arraylist scales well with the number of processors, vector does not even scale a bit although no contended locks should appear. Another scaliability problem I found is Memory-Management which seems to scale not at all, too … however the test was run on an IBM-JVM so I cannot speak about hotspots parallel GCs.

lg Clemens

Odd, I’ve never heard of Vector being suggested as faster than ArrayList. Given that ArrayList isn’t syncronised it should be the faster one, where did you come across this particular snippit of ‘wisdom’?

Well this is a quite general misunderstatement - since as far as I know ArrayList has different resizing charakteristis (more memory friedly).

and of course many more unprofesisonal statements spread all over the web. However too tired fir searching them :wink:

lg Clemens