bring back dependencies
This commit is contained in:
parent
adb14c2b95
commit
dccf0c3b0b
|
@ -1,6 +1,9 @@
|
|||
package com.baeldung.performance;
|
||||
|
||||
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.HashSet;
|
||||
|
@ -15,14 +18,14 @@ public class CollectionsBenchmark {
|
|||
private Set<Employee> employeeSet = new HashSet<>();
|
||||
private List<Employee> employeeList = new ArrayList<>();
|
||||
|
||||
private final long m_count = 16;
|
||||
private long iterations = 10000;
|
||||
|
||||
private Employee employee = new Employee(100L, "Harry");
|
||||
|
||||
@Setup(Level.Invocation)
|
||||
@Setup(Level.Trial)
|
||||
public void setUp() {
|
||||
|
||||
for (long ii = 0; ii < m_count; ii++) {
|
||||
for (long ii = 0; ii < iterations; ii++) {
|
||||
employeeSet.add(new Employee(ii, "John"));
|
||||
employeeList.add(new Employee(ii, "John"));
|
||||
|
||||
|
@ -35,19 +38,26 @@ public class CollectionsBenchmark {
|
|||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MINUTES)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Warmup(iterations = 1)
|
||||
public boolean testArrayList(MyState state) {
|
||||
return state.employeeList.contains(state.employee);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
@BenchmarkMode(Mode.AverageTime)
|
||||
@OutputTimeUnit(TimeUnit.MINUTES)
|
||||
@OutputTimeUnit(TimeUnit.NANOSECONDS)
|
||||
@Warmup(iterations = 1)
|
||||
public boolean testHashSet(MyState state) {
|
||||
return state.employeeSet.contains(state.employee);
|
||||
}
|
||||
|
||||
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…
Reference in New Issue