Skip to content

Commit 337a5df

Browse files
committed
changed examples of sort()
1 parent 3704450 commit 337a5df

1 file changed

Lines changed: 9 additions & 30 deletions

File tree

‎core-java-collections/src/main/java/com/baeldung/performance/ArraySortBenchmark.java‎

Lines changed: 9 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -20,48 +20,27 @@ public class ArraySortBenchmark {
2020
@State(Scope.Thread)
2121
public static class Initialize {
2222

23-
int iterations = 1000;
24-
25-
String[] array = new String[iterations];
26-
List<String> list = new ArrayList<>();
27-
28-
int[] intArray = new int[iterations];
29-
List<Integer> integerList = new ArrayList<>();
23+
String[] words = {"Java", "Baeldung", "Tutorial"};
24+
List<String> wordList = new ArrayList<>();
3025

3126
@Setup(Level.Trial)
3227
public void setUp() {
33-
for (int i = 0; i < iterations; i++) {
34-
array[i] = i + "";
35-
list.add(i + "");
36-
37-
intArray[i] = i;
38-
integerList.add(i);
39-
}
28+
wordList.add("Java");
29+
wordList.add("Baeldung");
30+
wordList.add("Tutorial");
4031
}
4132
}
4233

4334
@Benchmark
4435
public String[] benchmarkArraysSort(ArraySortBenchmark.Initialize state) {
45-
Arrays.sort(state.array);
46-
return state.array;
36+
Arrays.sort(state.words);
37+
return state.words;
4738
}
4839

4940
@Benchmark
5041
public List<String> benchmarkCollectionsSort(ArraySortBenchmark.Initialize state) {
51-
Collections.sort(state.list);
52-
return state.list;
53-
}
54-
55-
@Benchmark
56-
public int[] benchmarkArraysSortInt(ArraySortBenchmark.Initialize state) {
57-
Arrays.sort(state.intArray);
58-
return state.intArray;
59-
}
60-
61-
@Benchmark
62-
public List<Integer> benchmarkCollectionsSortInteger(ArraySortBenchmark.Initialize state) {
63-
Collections.sort(state.integerList);
64-
return state.integerList;
42+
Collections.sort(state.wordList);
43+
return state.wordList;
6544
}
6645

6746
public static void main(String[] args) throws Exception {

0 commit comments

Comments
 (0)