bring back dependencies
This commit is contained in:
parent
adb14c2b95
commit
dccf0c3b0b
@ -1,6 +1,9 @@
|
|||||||
package com.baeldung.performance;
|
package com.baeldung.performance;
|
||||||
|
|
||||||
import org.openjdk.jmh.annotations.*;
|
import org.openjdk.jmh.annotations.*;
|
||||||
|
import org.openjdk.jmh.runner.Runner;
|
||||||
|
import org.openjdk.jmh.runner.options.Options;
|
||||||
|
import org.openjdk.jmh.runner.options.OptionsBuilder;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
@ -15,14 +18,14 @@ public class CollectionsBenchmark {
|
|||||||
private Set<Employee> employeeSet = new HashSet<>();
|
private Set<Employee> employeeSet = new HashSet<>();
|
||||||
private List<Employee> employeeList = new ArrayList<>();
|
private List<Employee> employeeList = new ArrayList<>();
|
||||||
|
|
||||||
private final long m_count = 16;
|
private long iterations = 10000;
|
||||||
|
|
||||||
private Employee employee = new Employee(100L, "Harry");
|
private Employee employee = new Employee(100L, "Harry");
|
||||||
|
|
||||||
@Setup(Level.Invocation)
|
@Setup(Level.Trial)
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
|
|
||||||
for (long ii = 0; ii < m_count; ii++) {
|
for (long ii = 0; ii < iterations; ii++) {
|
||||||
employeeSet.add(new Employee(ii, "John"));
|
employeeSet.add(new Employee(ii, "John"));
|
||||||
employeeList.add(new Employee(ii, "John"));
|
employeeList.add(new Employee(ii, "John"));
|
||||||
|
|
||||||
@ -35,19 +38,26 @@ public class CollectionsBenchmark {
|
|||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
@BenchmarkMode(Mode.AverageTime)
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
@OutputTimeUnit(TimeUnit.MINUTES)
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
|
@Warmup(iterations = 1)
|
||||||
public boolean testArrayList(MyState state) {
|
public boolean testArrayList(MyState state) {
|
||||||
return state.employeeList.contains(state.employee);
|
return state.employeeList.contains(state.employee);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
@BenchmarkMode(Mode.AverageTime)
|
@BenchmarkMode(Mode.AverageTime)
|
||||||
@OutputTimeUnit(TimeUnit.MINUTES)
|
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||||
|
@Warmup(iterations = 1)
|
||||||
public boolean testHashSet(MyState state) {
|
public boolean testHashSet(MyState state) {
|
||||||
return state.employeeSet.contains(state.employee);
|
return state.employeeSet.contains(state.employee);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
org.openjdk.jmh.Main.main(args);
|
Options options = new OptionsBuilder()
|
||||||
|
.include(CollectionsBenchmark.class.getSimpleName()).threads(1)
|
||||||
|
.forks(1).shouldFailOnError(true)
|
||||||
|
.shouldDoGC(true)
|
||||||
|
.jvmArgs("-server").build();
|
||||||
|
new Runner(options).run();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user