Java tutorial
//package com.java2s; import java.util.List; import java.util.ListIterator; import java.util.Set; public class Main { public static long iterAdd(List list) { ListIterator iter = list.listIterator(); long start, stop, result = 0; for (int i = 0; i < 100; i++) { start = System.nanoTime(); iter.add(list.size() + 1 + i); stop = System.nanoTime(); result += stop - start; } return result / 100; } public static long add(List list) { long start, stop, result = 0; for (int i = 0; i < 100; i++) { start = System.nanoTime(); list.add(list.size() + 1 + i); stop = System.nanoTime(); result += stop - start; } return result / 100; } public static long add(Set set) { long start, stop, result = 0; for (int i = 0; i < 100; i++) { start = System.nanoTime(); set.add(set.size() + 1 + i); stop = System.nanoTime(); result += stop - start; } return result / 100; } }