java8 : parallel sort
This commit is contained in:
25
java8to11/src/parallelSort/App.java
Normal file
25
java8to11/src/parallelSort/App.java
Normal file
@@ -0,0 +1,25 @@
|
||||
package parallelSort;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Random;
|
||||
import java.util.stream.IntStream;
|
||||
|
||||
public class App {
|
||||
public static void main(String[] args) {
|
||||
int size = 1500;
|
||||
int[] numbers = new int[size];
|
||||
Random random = new Random();
|
||||
IntStream.range(0, size).forEach(i -> numbers[i] = random.nextInt());
|
||||
|
||||
long start = System.nanoTime();
|
||||
Arrays.sort(numbers);
|
||||
System.out.println("serial sorting took: " + (System.nanoTime() - start));
|
||||
|
||||
System.out.println("=====================================================");
|
||||
|
||||
IntStream.range(0, size).forEach(i -> numbers[i] = random.nextInt());
|
||||
start = System.nanoTime();
|
||||
Arrays.parallelSort(numbers);
|
||||
System.out.println("parallel sorting took: " + (System.nanoTime() - start));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user