Java Parallel Sort
Java 8 introduced .parallelSort() to the Array class. It uses multiple threads to perform the sort operation and is therefore quicker. Here’s some code to benchmark .parallelSort() against the regular .sort():
var numbers = new Random().ints(90000000, 1, 999999999);
int[] arrNumbers = numbers.toArray();
//List<Integer> lstNumbers = numbers.boxed().collect(Collectors.toList());
Date dtStart, dtEnd;
long diffInMillis = -1;
dtStart = new Date();
//Comment out the one to execute
//Arrays.sort(arrNumbers); //Takes ~6 seconds
//Arrays.parallelSort(arrNumbers); //Takes ~1 second
dtEnd = new Date();
diffInMillis = dtEnd.getTime() - dtStart.getTime();
System.out.print("Execution time: ");
System.out.println(diffInMillis);
With the above code, we get an execution time of 6 seconds for the .sort() execution and 1 second for the .parallelSort() execution on OpenJDK 17 running on an M1 Pro CPU.