changed examples of sort()
This commit is contained in:
parent
3704450509
commit
337a5dfbc8
|
@ -20,48 +20,27 @@ public class ArraySortBenchmark {
|
||||||
@State(Scope.Thread)
|
@State(Scope.Thread)
|
||||||
public static class Initialize {
|
public static class Initialize {
|
||||||
|
|
||||||
int iterations = 1000;
|
String[] words = {"Java", "Baeldung", "Tutorial"};
|
||||||
|
List<String> wordList = 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)
|
@Setup(Level.Trial)
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
for (int i = 0; i < iterations; i++) {
|
wordList.add("Java");
|
||||||
array[i] = i + "";
|
wordList.add("Baeldung");
|
||||||
list.add(i + "");
|
wordList.add("Tutorial");
|
||||||
|
|
||||||
intArray[i] = i;
|
|
||||||
integerList.add(i);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public String[] benchmarkArraysSort(ArraySortBenchmark.Initialize state) {
|
public String[] benchmarkArraysSort(ArraySortBenchmark.Initialize state) {
|
||||||
Arrays.sort(state.array);
|
Arrays.sort(state.words);
|
||||||
return state.array;
|
return state.words;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Benchmark
|
@Benchmark
|
||||||
public List<String> benchmarkCollectionsSort(ArraySortBenchmark.Initialize state) {
|
public List<String> benchmarkCollectionsSort(ArraySortBenchmark.Initialize state) {
|
||||||
Collections.sort(state.list);
|
Collections.sort(state.wordList);
|
||||||
return state.list;
|
return state.wordList;
|
||||||
}
|
|
||||||
|
|
||||||
@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 {
|
public static void main(String[] args) throws Exception {
|
||||||
|
|
Loading…
Reference in New Issue