1 import java.util.*; 2 import org.apache.avalon.excalibur.collections.VariableSizeBuffer; 3 import org.apache.avalon.excalibur.collections.FixedSizeBuffer; 4 5 public class ListTest 6 { 7 public static void main(String [] args) 8 { 9 int lInitialSize = Integer.parseInt(args[0]); 10 int lIterations = Integer.parseInt(args[1]); 11 ArrayList lArrayList = new ArrayList(lInitialSize + 1); 12 LinkedList lLinkedList = new LinkedList(); 13 VariableSizeBuffer lVariableSizeBuffer = new VariableSizeBuffer(lInitialSize + 1); 14 FixedSizeBuffer lFixedSizeBuffer = new FixedSizeBuffer(lInitialSize + 1); 15 long lBegin, lEnd; 16 17 for (int i = 0; i < lInitialSize; i++) 18 { 19 lArrayList.add(new Integer (i)); 20 lLinkedList.add(new Integer (i)); 21 lVariableSizeBuffer.add(new Integer (i)); 22 lFixedSizeBuffer.add(new Integer (i)); 23 } 24 25 lBegin = System.currentTimeMillis(); 26 for (int i = 0; i < lIterations; i++) 27 { 28 lArrayList.add(0, new Integer (i)); lArrayList.remove(lInitialSize); } 31 lEnd = System.currentTimeMillis(); 32 System.out.println("Time: " + (lEnd - lBegin)); 33 34 lBegin = System.currentTimeMillis(); 35 for (int i = 0; i < lIterations; i++) 36 { 37 lLinkedList.addFirst(new Integer (i)); lLinkedList.removeLast(); } 40 lEnd = System.currentTimeMillis(); 41 System.out.println("Time: " + (lEnd - lBegin)); 42 43 lBegin = System.currentTimeMillis(); 44 for (int i = 0; i < lIterations; i++) 45 { 46 lVariableSizeBuffer.add( new Integer (i) ); lVariableSizeBuffer.remove(); } 49 lEnd = System.currentTimeMillis(); 50 System.out.println("Time: " + (lEnd - lBegin)); 51 52 lBegin = System.currentTimeMillis(); 53 for (int i = 0; i < lIterations; i++) 54 { 55 lFixedSizeBuffer.add( new Integer (i) ); lFixedSizeBuffer.remove(); } 58 lEnd = System.currentTimeMillis(); 59 System.out.println("Time: " + (lEnd - lBegin)); 60 } 61 } 62 | Popular Tags |