-
Notifications
You must be signed in to change notification settings - Fork 5
/
ArrayListVsLinkedListDeletionStartTest.java
81 lines (65 loc) · 2.4 KB
/
ArrayListVsLinkedListDeletionStartTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
package com.coderstower.blog.java_collections_array_list_vs_linked_list.deletion;
import com.coderstower.blog.java_collections_array_list_vs_linked_list.ArrayListExecutionPlan;
import com.coderstower.blog.java_collections_array_list_vs_linked_list.LinkedListExecutionPlan;
import com.coderstower.blog.java_collections_array_list_vs_linked_list.Utils;
import org.junit.Test;
import org.openjdk.jmh.annotations.*;
import org.openjdk.jmh.results.Result;
import org.openjdk.jmh.results.RunResult;
import org.openjdk.jmh.runner.Runner;
import org.openjdk.jmh.runner.RunnerException;
import org.openjdk.jmh.runner.options.Options;
import org.openjdk.jmh.runner.options.OptionsBuilder;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat;
public class ArrayListVsLinkedListDeletionStartTest {
@Test
public void remove_start()
throws RunnerException, IOException {
Utils.populateToFile();
Options opt = new OptionsBuilder()
.include(
ArrayListVsLinkedListDeletionStartTest.class
.getSimpleName())
.detectJvmArgs()
.build();
Collection<RunResult> runResults = new Runner(opt)
.run();
Result arrayListResult = Utils
.find("arrayList",
runResults);
Result linkedListResult = Utils
.find("linkedList",
runResults);
assertThat(linkedListResult.getScore())
.isLessThan(arrayListResult.getScore());
}
@Benchmark
@Measurement(iterations = Utils.amountIterations, batchSize = 1, time = 1)
@BenchmarkMode(Mode.SingleShotTime)
@Fork(1)
@Warmup(iterations = 10)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public ArrayList<Integer> arrayList(
ArrayListExecutionPlan executionPlan) {
ArrayList<Integer> list = executionPlan.arrayList;
list.remove(0);
return list;
}
@Benchmark
@Measurement(iterations = Utils.amountIterations, batchSize = 1, time = 1)
@BenchmarkMode(Mode.SingleShotTime)
@Fork(1)
@Warmup(iterations = 10)
@OutputTimeUnit(TimeUnit.MILLISECONDS)
public LinkedList<Integer> linkedList(
LinkedListExecutionPlan executionPlan) {
LinkedList<Integer> list = executionPlan.linkedList;
list.remove(0);
return list;
}
}