File tree Expand file tree Collapse file tree
core-java-collections/src/main/java/com/baeldung/performance Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -22,30 +22,48 @@ public static class Initialize {
2222
2323 int iterations = 1000 ;
2424
25- int [] array = new int [iterations ];
26- List <Integer > list = new ArrayList <>();
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 <>();
2730
2831 @ Setup (Level .Trial )
2932 public void setUp () {
3033 for (int i = 0 ; i < iterations ; i ++) {
31- array [i ] = i ;
32- list .add (i );
34+ array [i ] = i + "" ;
35+ list .add (i + "" );
36+
37+ intArray [i ] = i ;
38+ integerList .add (i );
3339 }
3440 }
3541 }
3642
3743 @ Benchmark
38- public int [] benchmarkArraysSort (ArraySortBenchmark .Initialize state ) {
44+ public String [] benchmarkArraysSort (ArraySortBenchmark .Initialize state ) {
3945 Arrays .sort (state .array );
4046 return state .array ;
4147 }
4248
4349 @ Benchmark
44- public List <Integer > benchmarkCollectionsSort (ArraySortBenchmark .Initialize state ) {
50+ public List <String > benchmarkCollectionsSort (ArraySortBenchmark .Initialize state ) {
4551 Collections .sort (state .list );
4652 return state .list ;
4753 }
4854
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 ;
65+ }
66+
4967 public static void main (String [] args ) throws Exception {
5068 Options options = new OptionsBuilder ()
5169 .include (ArraySortBenchmark .class .getSimpleName ()).threads (1 )
You can’t perform that action at this time.
0 commit comments