[BAEL-4495] - Add test for case when 2nd collection is also hashset (#10175)
* [BAEL-4495] Performance of removeAll() in a HashSet * [BAEL-4495] Add unit test for hashset removeAll() * [BAEL-4495] Update test methods to camelCase * [BAEL-4495] Add test for case when 2nd collection is also hashset
This commit is contained in:
parent
44265c62c9
commit
000275f9f7
|
@ -33,11 +33,15 @@ public class HashSetBenchmark {
|
|||
private List<Employee> employeeList1 = new ArrayList<>();
|
||||
private Set<Employee> employeeSet2 = new HashSet<>();
|
||||
private List<Employee> employeeList2 = new ArrayList<>();
|
||||
private Set<Employee> employeeSet3 = new HashSet<>();
|
||||
private Set<Employee> employeeSet4 = new HashSet<>();
|
||||
|
||||
private long set1Size = 60000;
|
||||
private long list1Size = 50000;
|
||||
private long set2Size = 50000;
|
||||
private long list2Size = 60000;
|
||||
private long set3Size = 50000;
|
||||
private long set4Size = 60000;
|
||||
|
||||
@Setup(Level.Trial)
|
||||
public void setUp() {
|
||||
|
@ -57,6 +61,14 @@ public class HashSetBenchmark {
|
|||
for (long i = 0; i < list2Size; i++) {
|
||||
employeeList2.add(new Employee(i, RandomStringUtils.random(7, true, false)));
|
||||
}
|
||||
|
||||
for (long i = 0; i < set3Size; i++) {
|
||||
employeeSet3.add(new Employee(i, RandomStringUtils.random(7, true, false)));
|
||||
}
|
||||
|
||||
for (long i = 0; i < set4Size; i++) {
|
||||
employeeSet4.add(new Employee(i, RandomStringUtils.random(7, true, false)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -71,6 +83,11 @@ public class HashSetBenchmark {
|
|||
public boolean given_SizeOfHashsetSmallerThanSizeOfCollection_When_RemoveAllFromHashSet_Then_BadPerformance(MyState state) {
|
||||
return state.employeeSet2.removeAll(state.employeeList2);
|
||||
}
|
||||
|
||||
@Benchmark
|
||||
public boolean given_SizeOfHashsetSmallerThanSizeOfAnotherHashSet_When_RemoveAllFromHashSet_Then_GoodPerformance(MyState state) {
|
||||
return state.employeeSet3.removeAll(state.employeeSet4);
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
Options options = new OptionsBuilder().include(HashSetBenchmark.class.getSimpleName())
|
||||
|
|
Loading…
Reference in New Issue