import java.util.Random;
public class QueueTest {
private static double testStack(Queue<Integer> queue, int opCount) {
long startTime = System.nanoTime();
Random random = new Random();
for (int i = 0; i < opCount; i++) {
queue.enqueue(random.nextInt(Integer.MAX_VALUE));
}
for (int i = 0; i < opCount; i++) {
queue.dequeue();
}
long endTime = System.nanoTime();
return (endTime - startTime) / 1000000000.0;
}
public static void main(String[] args) {
int opCount = 100000;
ArrayQueue<Integer> arrayQueue = new ArrayQueue<>();
double time1 = testStack(arrayQueue, opCount);
System.out.println("ArrayQueue,time:"+time1+"s");
LoopQueue<Integer> loopQueue = new LoopQueue<>();
double time2 = testStack(loopQueue, opCount);
System.out.println("LoopQueue,time:"+time2+"s");
LinkedListQueue<Integer> linkedListQueue = new LinkedListQueue<>();
double time3= testStack(linkedListQueue, opCount);
System.out.println("LinkedListQueue,time:"+time3+"s");
}
}
测试结果