// requires LinkedList.java and CircQ.java public class Qtest { public static void main(String[] argv) { int n = 1000000; // number of values to add/delete int cap = n; // initial capacity of CircQ if (argv.length>0) n = Integer.parseInt(argv[0]); if (argv.length>1) cap = Integer.parseInt(argv[1]); // test speed of LinkedList long t1 = System.currentTimeMillis(); Queue LL = new LinkedList(); for(Integer i=n;i>0;i--) LL.push(i); for(Integer i=n;i>0;i--) LL.pop(); long t2 = System.currentTimeMillis(); // test speed of CircOQ, with resizing ability Queue CQ = new CircOQ(cap); for(Integer i=n;i>0;i--) CQ.push(i); for(Integer i=n;i>0;i--) CQ.pop(); long t3 = System.currentTimeMillis(); System.out.println("Time for LinkedList: "+(t2-t1)+"ms"); System.out.println("Time for CircOQ: "+(t3-t2)+"ms"); }//main } /* This test shows that the circular queue implementation is much faster for moderately sized values of n (up to about 4 million), even with dynamic resizing of the queue, as long as resize doubles the queue capacity each time. However, as the size of n increases further, the difference fluxuates. This test is not scientific. It only tests push/pop of Integer objects. It also only applies to Java, because other languages may use a different heap allocation algorithm. The times are also dependent on whether and how often the garbage collector is in use. The CircOQ implementation is at least just as efficient as LinkedList memory-wise, even if the capacity is twice the size, because linked lists requires a 'next' pointer for each node in the list. */