more tests

This commit is contained in:
mherbaghinyan 2019-02-08 14:55:23 +04:00
parent 627a493f8f
commit 3704450509
1 changed files with 24 additions and 6 deletions

View File

@ -22,30 +22,48 @@ public class ArraySortBenchmark {
int iterations = 1000;
int[] array = new int[iterations];
List<Integer> list = new ArrayList<>();
String[] array = new String[iterations];
List<String> list = new ArrayList<>();
int[] intArray = new int[iterations];
List<Integer> integerList = new ArrayList<>();
@Setup(Level.Trial)
public void setUp() {
for (int i = 0; i < iterations; i++) {
array[i] = i;
list.add(i);
array[i] = i + "";
list.add(i + "");
intArray[i] = i;
integerList.add(i);
}
}
}
@Benchmark
public int[] benchmarkArraysSort(ArraySortBenchmark.Initialize state) {
public String[] benchmarkArraysSort(ArraySortBenchmark.Initialize state) {
Arrays.sort(state.array);
return state.array;
}
@Benchmark
public List<Integer> benchmarkCollectionsSort(ArraySortBenchmark.Initialize state) {
public List<String> benchmarkCollectionsSort(ArraySortBenchmark.Initialize state) {
Collections.sort(state.list);
return state.list;
}
@Benchmark
public int[] benchmarkArraysSortInt(ArraySortBenchmark.Initialize state) {
Arrays.sort(state.intArray);
return state.intArray;
}
@Benchmark
public List<Integer> benchmarkCollectionsSortInteger(ArraySortBenchmark.Initialize state) {
Collections.sort(state.integerList);
return state.integerList;
}
public static void main(String[] args) throws Exception {
Options options = new OptionsBuilder()
.include(ArraySortBenchmark.class.getSimpleName()).threads(1)