|
A pair of programs are included in the source code which give a simple
performance comparison between several different types of array-like
collections. The first program, Java version 1.3.0 Java HotSpot(TM) Client VM 1.3.0-C Sun Microsystems Inc. Running initialization pass... Running tests adding 50000 values to each collection with 1000 cycles for each collection type. Ran int[] add test in 1.8 seconds Ran DirectIntArray add test in 8.1 seconds Ran IntArray add test in 8.6 seconds Ran IntegerArray add test in 48.7 seconds Ran ObjectArray of Integer add test in 48.8 seconds Ran ArrayList of Integer add test in 48.2 seconds Ran Vector of Integer add test in 49.7 seconds For this test, which is only repeatedly creating the collection and
filling it with values, it's obvious that the simple array (
After these there's another dramatic jump in execution time to the remaining
alternatives. These are all object collections, so they require the
The second program, Java version 1.3.0 Java HotSpot(TM) Client VM 1.3.0-C Sun Microsystems Inc. Starting test run with 25000 values to be sorted. Ran int[] sort test in 5.4 seconds Ran DirectIntArray sort test in 12.1 seconds Ran IntArray sort test in 12.0 seconds Ran IntegerArray sort test in 36.9 seconds Ran ObjectArray of Integer sort test in 37.2 seconds Ran ArrayList of Integer sort test in 47.9 seconds Ran Vector of Integer sort test in 44.2 seconds Here again, the simple array is the best by a sizable
margin. There's still a big jump in execution time to the remaining
alternatives, but for this test those alternatives are not as close as before.
The object collections based on the type-specific collections library code,
What these tests show is that if you really need the best performance, find a way to use a simple array for your data manipulation. Failing that, the type-specific collections library gives much better performance for primitive values and significantly better performance for object values than the standard Java collections. |