비교
ArrayList<Integer> arrayList = new ArrayList<>();
LinkedList<Integer> linkedList = new LinkedList<>();
System.out.println("뒤에 추가");
int count1 = 10_000_000;
listAdd(arrayList, count1);
listAdd(linkedList, count1);
System.out.println("앞부터 삭제");
int count4 = 1_000;
listRemoveHead(arrayList, count4);
listRemoveHead(linkedList, count4);
}
뒤에 추가
0.194 sec
0.896 sec
앞부터 삭제
5.199 sec
0.0 sec
System.out.println("뒤에 추가");
int count1 = 10_000_000;
listAdd(arrayList, count1);
listAdd(linkedList, count1);
System.out.println("중간 추가");
int count2 = 5_000;
listAddMiddle(arrayList, count2);
listAddMiddle(linkedList, count2);
System.out.println("앞부터 삭제");
int count4 = 1_000;
listRemoveHead(arrayList, count4);
listRemoveHead(linkedList, count4);
뒤에 추가
0.19 sec
0.899 sec
중간 추가
27.783 sec
0.006 sec
앞부터 삭제
5.871 sec
0.0 sec
System.out.println("뒤에 추가");
int count1 = 10_000_000;
listAdd(arrayList, count1);
listAdd(linkedList, count1);
System.out.println("뒤부터 삭제");
int count3 = 5_000_000;
listRemoveBack(arrayList, count3);
listRemoveBack(linkedList, count3);
System.out.println("앞부터 삭제");
int count4 = 1_000;
listRemoveHead(arrayList, count4);
listRemoveHead(linkedList, count4);
뒤에 추가
0.2 sec
0.89 sec
뒤부터 삭제
0.393 sec
0.053 sec
앞부터 삭제
1.8 sec
0.0 sec
System.out.println("뒤에 추가");
int count1 = 10_000_000;
listAdd(arrayList, count1);
listAdd(linkedList, count1);
System.out.println("중간 삭제");
int count5 = 1_000;
listRemoveMiddle(arrayList, count5);
listRemoveMiddle(linkedList, count5);
뒤에 추가
0.196 sec
0.907 sec
중간 삭제
4.772 sec
4.526 sec
System.out.println("뒤에 추가");
int count1 = 10_000_000;
listAdd(arrayList, count1);
listAdd(linkedList, count1);
System.out.println("앞부터 조회");
int count6 = 100_000;
listGetHead(arrayList, count6);
listGetHead(linkedList, count6);
뒤에 추가
0.193 sec
0.924 sec
앞부터 조회
0.004 sec
9.245 sec
private static void listAdd(List<Integer> list, Integer count) {
long start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
list.add(i);
}
System.out.println((System.currentTimeMillis() - start) / 1000f + " sec");
}
private static void listAddMiddle(List<Integer> list, Integer count) {
long start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
list.add(500, i);
}
System.out.println((System.currentTimeMillis() - start) / 1000f + " sec");
}
private static void listRemoveBack(List<Integer> list, Integer count) {
long start = System.currentTimeMillis();
for (int i = list.size() - 1; count > 0; i--, count--) {
list.remove(i);
}
System.out.println((System.currentTimeMillis() - start) / 1000f + " sec");
}
private static void listRemoveMiddle(List<Integer> list, Integer count) {
long start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
list.remove(1_000_000);
}
System.out.println((System.currentTimeMillis() - start) / 1000f + " sec");
}
private static void listRemoveHead(LinkedList<Integer> list, Integer count) {
long start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
list.remove();
}
System.out.println((System.currentTimeMillis() - start) / 1000f + " sec");
}
private static void listRemoveHead(ArrayList<Integer> list, Integer count) {
long start = System.currentTimeMillis();
for (int i = 0; i < count; i++) {
list.remove(0);
}
System.out.println((System.currentTimeMillis() - start) / 1000f + " sec");
}
private static void listGetHead(List<Integer> list, Integer count) {
long start = System.currentTimeMillis();
int sum = 0;
for (int i = 0; i < count; i++) {
sum += list.get(i);
}
System.out.println((System.currentTimeMillis() - start) / 1000f + " sec");
}