

Three test classes of different sizes were created to be stored within the ArrayLists, one class had two long fields, one had four long fields, and finally one with eight long fields. The first was reproduced by simply reading the first field of every element of the list in order, and the second by sorting the list based on the object’s fields (with a simple quicksort).

A couple of warmup iteration were always run and discarded. Multiple iterations were run, and unless stated results were calculated with a 99% confidence interval.
#JAVA ARRAY VS ARRAYLIST EFFICIENCY CODE#
The new JMH benchmark framework was used, and final benchmark code is available here.
#JAVA ARRAY VS ARRAYLIST EFFICIENCY SERIES#
To test the performance of this new style of list, a series of benchmarks were devised. This article aims to benchmark this list, and understand its unique characteristics. This has the unique property of keeping all objects contiguous in memory, and avoids a pointer indirection, at the cost of needing to copy values in and out. Previously we introduced a UnsafeArrayList, an ArrayList style collection that instead of storing references to the objects, it would use and UnsafeHelper to copy the objects into heap allocated memory.
