Language/Java

[펌] java Queue 종류별 성능 비교

아르비스 2016. 10. 14. 13:05

http://yjacket.tistory.com/48


왠만하면  LinkedList 쓰거나  ArrayDeque 써야 할듯.


결과

ArrayList - 넣기 : 38ms
ArrayList - 빼기 : 36851ms
HashMap - 넣기 : 170ms
HashMap - 빼기 : 17ms
ConcurrentLinkedQueue - 넣기 : 156ms
ConcurrentLinkedQueue - 빼기 : 17ms
LinkedList - 넣기 : 41ms
LinkedList - 빼기 : 9ms
ArrayBlockingQueue - 넣기 : 32ms
ArrayBlockingQueue - 빼기 : 22ms
ArrayDeque - 넣기 : 17ms
ArrayDeque - 빼기 : 5ms
LinkedBlockingQueue - 넣기 : 47ms
LinkedBlockingQueue - 빼기 : 32ms
LinkedBlockingDeque - 넣기 : 100ms
LinkedBlockingDeque - 빼기 : 24ms
PriorityBlockingQueue - 넣기 : 68ms
PriorityBlockingQueue - 빼기 : 188ms
SynchronousQueue - 넣기 : 7ms
SynchronousQueue - 빼기 : 4ms
PriorityQueue - 넣기 : 16ms
PriorityQueue - 빼기 : 164ms

테스트코드


import java.util.ArrayDeque;
import java.util.LinkedList;
import java.util.PriorityQueue;
import java.util.Queue;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.LinkedBlockingDeque;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.SynchronousQueue;

import com.gytni.imon3lib.util.StopWatch;


public class QueueTest
{
public static void main(String[] args)
{
Q1 q1 = new Q1();
Q2 q2 = new Q2();
Queue<Integer> q3 = new ConcurrentLinkedQueue<Integer>();
Queue<Integer> q4 = new LinkedList<Integer>();
Queue<Integer> q5 = new ArrayBlockingQueue<Integer>(300000);
Queue<Integer> q6 = new ArrayDeque<Integer>();
Queue<Integer> q7 = new LinkedBlockingQueue<Integer>();
Queue<Integer> q8 = new LinkedBlockingDeque<Integer>();
Queue<Integer> q9 = new PriorityBlockingQueue<Integer>();
Queue<Integer> q0 = new SynchronousQueue<Integer>();
Queue<Integer> qa = new PriorityQueue<Integer>();
StopWatch.start();
for (int i = 0; i < 300000; i++)
q1.offer(i);
StopWatch.stop("ArrayList - 넣기");
for (int i = 0; i < 300000; i++)
q1.poll();
StopWatch.stop("ArrayList - 빼기");
for (int i = 0; i < 300000; i++)
q2.offer(i);
StopWatch.stop("HashMap - 넣기");
for (int i = 0; i < 300000; i++)
q2.poll();
StopWatch.stop("HashMap - 빼기");
for (int i = 0; i < 300000; i++)
q3.offer(i);
StopWatch.stop("ConcurrentLinkedQueue - 넣기");
for (int i = 0; i < 300000; i++)
q3.poll();
StopWatch.stop("ConcurrentLinkedQueue - 빼기");
for (int i = 0; i < 300000; i++)
q4.offer(i);
StopWatch.stop("LinkedList - 넣기");
for (int i = 0; i < 300000; i++)
q4.poll();
StopWatch.stop("LinkedList - 빼기");
for (int i = 0; i < 300000; i++)
q5.offer(i);
StopWatch.stop("ArrayBlockingQueue - 넣기");
for (int i = 0; i < 300000; i++)
q5.poll();
StopWatch.stop("ArrayBlockingQueue - 빼기");
for (int i = 0; i < 300000; i++)
q6.offer(i);
StopWatch.stop("ArrayDeque - 넣기");
for (int i = 0; i < 300000; i++)
q6.poll();
StopWatch.stop("ArrayDeque - 빼기");
for (int i = 0; i < 300000; i++)
q7.offer(i);
StopWatch.stop("LinkedBlockingQueue - 넣기");
for (int i = 0; i < 300000; i++)
q7.poll();
StopWatch.stop("LinkedBlockingQueue - 빼기");
for (int i = 0; i < 300000; i++)
q8.offer(i);
StopWatch.stop("LinkedBlockingDeque - 넣기");
for (int i = 0; i < 300000; i++)
q8.poll();
StopWatch.stop("LinkedBlockingDeque - 빼기");
for (int i = 0; i < 300000; i++)
q9.offer(i);
StopWatch.stop("PriorityBlockingQueue - 넣기");
for (int i = 0; i < 300000; i++)
q9.poll();
StopWatch.stop("PriorityBlockingQueue - 빼기");
for (int i = 0; i < 300000; i++)
q0.offer(i);
StopWatch.stop("SynchronousQueue - 넣기");
for (int i = 0; i < 300000; i++)
q0.poll();
StopWatch.stop("SynchronousQueue - 빼기");
for (int i = 0; i < 300000; i++)
qa.offer(i);
StopWatch.stop("PriorityQueue - 넣기");
for (int i = 0; i < 300000; i++)
qa.poll();
StopWatch.stop("PriorityQueue - 빼기");
}
}