I ran some tests. It's not a perfect test but it gives a notion on the performance differences.
The program:
import java.util.*; import java.util.concurrent.*; public class Main { public static void main(String[] args) { testCollection(new ArrayList<Integer>()); testCollection(Collections.synchronizedList(new ArrayList<Integer>())); testCollection(new CopyOnWriteArrayList<Integer>()); testCollection(new LinkedList<Integer>()); testCollection(Collections.synchronizedList(new LinkedList<Integer>())); testCollection(Collections.newSetFromMap(new ConcurrentHashMap<Integer, Boolean>())); testCollection(new ConcurrentLinkedQueue<Integer>()); testCollection(new ConcurrentSkipListSet<Integer>()); } static void testCollection(Collection<Integer> collection) { testCollection(collection, 3); } static void testCollection(Collection<Integer> collection, int count) { Test t = new Test(collection); for (int i = 0; i < 10; i++) System.gc(); while (count > 0) { long time = 0, iterationTime; for (int x = 0; x < 1010; x++) { iterationTime = t.timeIteration(); if (x >= 10) { // skip first 10 runs results to reduce the effect of runtime optimizations time += iterationTime; } } System.out.println(collection.getClass() + ": " + time / 1000000.0 + " milliseconds"); count--; } } static class Test { private Collection<Integer> list; public Test(Collection<Integer> list) { list.addAll(Arrays.asList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10)); this.list = list; } long timeIteration() { Iterator<Integer> iterator; long start = System.nanoTime(); for (int i = 0; i < 10000; i++) { for (iterator = list.iterator(); iterator.hasNext(); ) { Integer x = iterator.next(); if (x > 20) System.out.println("this doesn't happen"); } } return System.nanoTime() - start; } } }
The results: (Formatted for clarity)
╔══════════════════════════════════════════╦══════════════╗ ║ class (java.util.) ║ milliseconds ║ ╠══════════════════════════════════════════╬══════════════╣ ║ ArrayList ║ 138.242208 ║ ║------------------------------------------║--------------║ ║ ArrayList ║ 135.795334 ║ ║------------------------------------------║--------------║ ║ ArrayList ║ 160.516023 ║ ║------------------------------------------║--------------║ ║ Collections$SynchronizedRandomAccessList ║ 371.29873 ║ ║------------------------------------------║--------------║ ║ Collections$SynchronizedRandomAccessList ║ 318.442416 ║ ║------------------------------------------║--------------║ ║ Collections$SynchronizedRandomAccessList ║ 335.079316 ║ ║------------------------------------------║--------------║ ║ concurrent.CopyOnWriteArrayList ║ 299.203427 ║ ║------------------------------------------║--------------║ ║ concurrent.CopyOnWriteArrayList ║ 361.800762 ║ ║------------------------------------------║--------------║ ║ concurrent.CopyOnWriteArrayList ║ 316.672923 ║ ║------------------------------------------║--------------║ ║ LinkedList ║ 776.843317 ║ ║------------------------------------------║--------------║ ║ LinkedList ║ 807.458514 ║ ║------------------------------------------║--------------║ ║ LinkedList ║ 793.940155 ║ ║------------------------------------------║--------------║ ║ Collections$SynchronizedList ║ 793.125156 ║ ║------------------------------------------║--------------║ ║ Collections$SynchronizedList ║ 782.003326 ║ ║------------------------------------------║--------------║ ║ Collections$SynchronizedList ║ 790.937425 ║ ║------------------------------------------║--------------║ ║ Collections$SetFromMap ║ 1452.049046 ║ ║------------------------------------------║--------------║ ║ Collections$SetFromMap ║ 1457.275127 ║ ║------------------------------------------║--------------║ ║ Collections$SetFromMap ║ 1450.322531 ║ ║------------------------------------------║--------------║ ║ concurrent.ConcurrentLinkedQueue ║ 976.803439 ║ ║------------------------------------------║--------------║ ║ concurrent.ConcurrentLinkedQueue ║ 855.64423 ║ ║------------------------------------------║--------------║ ║ concurrent.ConcurrentLinkedQueue ║ 845.05258 ║ ║------------------------------------------║--------------║ ║ concurrent.ConcurrentSkipListSet ║ 926.423234 ║ ║------------------------------------------║--------------║ ║ concurrent.ConcurrentSkipListSet ║ 924.370203 ║ ║------------------------------------------║--------------║ ║ concurrent.ConcurrentSkipListSet ║ 933.504106 ║ ╚══════════════════════════════════════════╩══════════════╝
Comments are welcome.