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 1111import java .util .List ;
1212import java .util .concurrent .TimeUnit ;
1313
14- @ BenchmarkMode (Mode .AverageTime )
15- @ OutputTimeUnit (TimeUnit .NANOSECONDS )
14+ @ BenchmarkMode (Mode .SingleShotTime )
15+ @ OutputTimeUnit (TimeUnit .MINUTES )
1616@ Measurement (batchSize = 100000 , iterations = 10 )
1717@ Warmup (batchSize = 100000 , iterations = 10 )
1818public class ArraySortBenchmark {
1919
2020 @ State (Scope .Thread )
2121 public static class Initialize {
2222
23- String [] array = new String []{ "A" , "AB" , "B" } ;
23+ int iterations = 1000 ;
2424
25- List <String > list = new ArrayList <>();
25+ int [] array = new int [iterations ];
26+
27+ List <Integer > list = new ArrayList <>();
2628
2729 @ Setup (Level .Trial )
2830 public void setUp () {
29- list .add ("A" );
30- list .add ("AB" );
31- list .add ("B" );
31+
32+ for (int i = 0 ; i < iterations ; i ++) {
33+ array [i ] = i ;
34+ list .add (i );
35+ }
3236 }
3337
3438 }
3539
3640 @ Benchmark
37- public String [] benchmarkArraysSort (ArraySortBenchmark .Initialize state ) {
41+ public int [] benchmarkArraysSort (ArraySortBenchmark .Initialize state ) {
3842 Arrays .sort (state .array );
3943 return state .array ;
4044 }
4145
4246 @ Benchmark
43- public List <String > benchmarkCollectionsSort (ArraySortBenchmark .Initialize state ) {
47+ public List <Integer > benchmarkCollectionsSort (ArraySortBenchmark .Initialize state ) {
4448 Collections .sort (state .list );
4549 return state .list ;
4650 }
You can’t perform that action at this time.
0 commit comments