@@ -12,10 +12,14 @@ final class ParallelRadixSortBenchmark {
1212 private static final int MAXIMUM_SKIP_LAST_ELEMENTS = 1711 ;
1313
1414 public static void main (String [] args ) {
15- System .out .println ("Warming up..." );
15+ System .out .println ("Warming up benchmark 1 ..." );
1616 benchmark (false );
17- System .out .println ("Benchmarking..." );
17+ System .out .println ("Warming up benchmark 2..." );
18+ benchmark2 (false );
19+ System .out .println ("Benchmarking 1..." );
1820 benchmark (true );
21+ System .out .println ("Benchmarking 2..." );
22+ benchmark2 (true );
1923 System .out .println ("Benchmark done!" );
2024 }
2125
@@ -25,7 +29,6 @@ private static void benchmark(boolean print) {
2529 long totalDuration2 = 0L ;
2630
2731 for (int iteration = 0 ; iteration < BENCHMARK_ITERATIONS ; iteration ++) {
28- System .gc ();
2932
3033 int arrayLength =
3134 MINIMUM_ARRAY_SIZE +-
@@ -71,4 +74,56 @@ private static void benchmark(boolean print) {
7174 + totalDuration2 );
7275 }
7376 }
77+
78+ private static void benchmark2 (boolean print ) {
79+ Random random = new Random ();
80+ long totalDuration1 = 0L ;
81+ long totalDuration2 = 0L ;
82+
83+ for (int iteration = 0 ; iteration < BENCHMARK_ITERATIONS ; iteration ++) {
84+
85+ int arrayLength =
86+ MINIMUM_ARRAY_SIZE +-
87+ random .nextInt (MAXIMUM_ARRAY_SIZE - MINIMUM_ARRAY_SIZE + 1 );
88+
89+ int [] array1 = new int [arrayLength ];
90+ int [] array2 = array1 .clone ();
91+
92+ int fromIndex = random .nextInt (MAXIMUM_FROM_INDEX + 1 );
93+ int toIndex = array1 .length -
94+ random .nextInt (MAXIMUM_SKIP_LAST_ELEMENTS + 1 );
95+
96+ long startTime = System .currentTimeMillis ();
97+ Arrays .parallelSort (array1 , fromIndex , toIndex );
98+ long endTime = System .currentTimeMillis ();
99+ long duration1 = endTime - startTime ;
100+ totalDuration1 += duration1 ;
101+
102+ startTime = System .currentTimeMillis ();
103+ ParallelRadixSort .parallelSort (array2 , fromIndex , toIndex );
104+ endTime = System .currentTimeMillis ();
105+ long duration2 = endTime - startTime ;
106+ totalDuration2 += duration2 ;
107+
108+ boolean agreed = Arrays .equals (array1 , array2 );
109+
110+ if (print ) {
111+ System .out .println (
112+ "Arrays.parallelSort: "
113+ + duration1
114+ + " ms, ParallelRadixSort.parallelSort: "
115+ + duration2
116+ + " ms, agreed: "
117+ + agreed );
118+ }
119+ }
120+
121+ if (print ) {
122+ System .out .println (
123+ "Total Arrays.parallelSort duration: "
124+ + totalDuration1
125+ + ", total ParallelRadixSort.parallelSort: "
126+ + totalDuration2 );
127+ }
128+ }
74129}
0 commit comments