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