23.12 sort/parallelSort Timings with the Java SE 8 Date/Time API

In Section 7.15, we used class Arrays’s static method sort to sort an array and we introduced static method parallelSort for sorting large arrays more efficiently on multicore systems. Figure 23.28 uses both methods to sort 15,000,000 element arrays of random int values so that we can demonstrate parallelSort’s performance improvement of over sort on a multi-core system (we ran this on a dual-core system).

 1   // SortComparison.java 2   // Comparing performance of Arrays methods sort and parallelSort. 3   import java.time.Duration; 4   import java.time.Instant; 5   import java.text.NumberFormat; 6   import java.util.Arrays; 7   import java.security.SecureRandom; ...

Get Java™ How To Program (Early Objects), Tenth Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.